4

I have a generic function which I want to get three values from. However it only returns one of the values from the "return" function. My code is structured like this:

doEverythingFunction <- function(x){

    "do some esoteric calculations here"
    return(valueX)
    "do some more esoteric calculations here"
    return(valueY)
    "do even more esoteric calculations here"
    return(valueZ)
}

This function only returns value Z and not X and Y. How can I get it to return all three values?

Sotos
  • 51,121
  • 6
  • 32
  • 66
pd441
  • 2,644
  • 9
  • 30
  • 41

1 Answers1

7

In R you can only return one object. You could put the three values in a list or a vector and then return that list or vector.

Oriol Mirosa
  • 2,756
  • 1
  • 13
  • 15