[R] apply on function with vector as result
Christof Kluß
ckluss at email.uni-kiel.de
Fri Dec 9 15:24:49 CET 2011
Am 09-12-2011 12:54, schrieb Sarah Goslee:
>> myfunc<- function(x) {a=x; b=x-1; c(a, b) }
>> ys<- sapply(1:5, myfunc)
>> ys
> [,1] [,2] [,3] [,4] [,5]
> [1,] 1 2 3 4 5
> [2,] 0 1 2 3 4
>
> And from there, it's not at all clear what you mean by "one vector" -
> in what order? All of the a then all of the b values? abab?
>
> as.vector(ys) and as.vector(t(ys)) will accomplish those.
>
> Or do you mean simply
> as<- ys[1,]
> bs<- ys[2,]
Thank you very much! That is what I was looking for. Sorry that I have
expressed myself so unclear.
Greetings
Christof
More information about the R-help
mailing list