Can you assign two variables simultaneously in R?

后端 未结 2 1519
情话喂你
情话喂你 2021-01-25 00:06

I am using the example of calculating the length of the arc around a circle and the area under the arc around a circle based on the radius of the circle (r) and the angle of the

2条回答
  •  遇见更好的自我
    2021-01-25 00:41

    As Gregor said, there's no way to do it exactly as you said and his method is a good one, but you could also have a vector represent your two values like so:

    # Function that adds one value and returns a vector of all the arguments.
    plusOne <- function(vec) {
    
      vec <- vec + 1
      return(vec)
    
    }
    
    # Creating variables and applying the function.
    x <- 1
    y <- 2
    z <- 3
    vec <- c(x, y, z)
    vec <- plusOne(vec)
    

    So essentially you could make a vector and have your function return vectors, which is essentially filling 3 values at once. Again, not what you want exactly, just a suggestion.

提交回复
热议问题