R 从函数返回多个值

R 从函数返回多个值,r,function,R,Function,我有一个通用函数,我想从中得到三个值。但是,它仅从“return”函数返回一个值。我的代码的结构如下: doEverythingFunction <- function(x){ "do some esoteric calculations here" return(valueX) "do some more esoteric calculations here" return(valueY) "do even more esoteric calcu

我有一个通用函数,我想从中得到三个值。但是,它仅从“return”函数返回一个值。我的代码的结构如下:

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)
}

doEverythingFunction在R中只能返回一个对象。您可以将这三个值放入一个列表或向量中,然后返回该列表或向量。

return(list(valueX,valueY,valueZ))
只需在末尾返回一个值,即
return(list(valueX,valueY,valueZ))