Skip to content
Prev 279854 / 398506 Next

apply on function with vector as result

Hi,

a have some code like

myfunc <- function(x) { ...;  return c(a,b) }

ys <- sapply(0:100,myfunc)

so I get something like c(c(a1,b1),c(a2,b2),...)

But now I need the "as" and "bs" in one vector

as <- apply(ys, function(c(a,b)) a)
bs <- apply(ys, function(c(a,b)) b)

Can you help me with the correct syntax, instead of my pseudo code?

thx
Christof