I have a function that takes a vector and returns some output.
my.function <- function(x){
if (1 %in% x) {
first.data <- data.frame(a = c(1, 2), b = c("a", "b"))
return(first.data)
}
if (2 %in% x){
second.data <- data.frame(a = c("I", "II"), b = c("a", "b"))
return(second.data)
}}
my.function(x = c(1, 2))
a b
1 a
2 b
Why does my function not return both first.data as well as second.data?
lapply(c(1, 2), my.function)? OrVectorize(my.function, SIMPLIFY = F)your function.returncommand in a function and not multiplereturn?