Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return multiple values from a function [duplicate]

Tags:

function

r

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?

like image 855
steve zissou Avatar asked Sep 12 '25 10:09

steve zissou


1 Answers

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.

like image 71
Oriol Mirosa Avatar answered Sep 14 '25 00:09

Oriol Mirosa