Reputation: 5355
I want to write values into an R list. For this I have created a test program:
testWriteToList <- function() {
for (i in seq(1:10)) {
x <- i
y <- i+1
list <- list(c(x,y))
}
return(list)
}
(testWriteToList())
However, as output I get:
[[1]]
[1] 10 11
In fact, I want all the ouput in a list. How to do that?
I appreciate your answer!!!
Upvotes: 0
Views: 33
Reputation: 61214
You can change your entire loop to lapply
lapply(1:10, function(i) c(i, i+1))
Upvotes: 1