[R] combine vectors in an alternating way
Ben Bolker
bbolker at gmail.com
Wed Oct 20 14:18:50 CEST 2010
fugelpitch <jonas <at> runtimerecords.net> writes:
> I have two vectors
>
> min
> 0.2, 0.3, 0.6, 0.1
>
> max
> 0.4,0.5,0.7,0.4
>
> Is there a way to combine these two vector so that the values will be taken
> from the vectors alternating so that I will get a new
> minmaxminmaxminmax-vector?
>
> minmax
> 0.2,0.4,0.3,0.5,0.6,0.7,0.1,0.4
>
c(rbind(min,max))
[i.e., combine the vectors into a two-row matrix
and then flatten it, using the special knowledge
that R stores matrices in column-wise order]
More information about the R-help
mailing list