[R] Conditional Splitting a Vectors into Two Vectors
Peter Ehlers
ehlers at ucalgary.ca
Tue Jul 6 08:59:24 CEST 2010
On 2010-07-06 0:39, Gundala Viswanath wrote:
> Suppose I have two vectors of same dimensions:
>
> x<-c(0.49534,0.80796,0.93970,0.99998)
> count<-c(0,33,0,4)
>
> How can I group the vectors 'x' into two vectors:
>
> 1. Vector `grzero` that contain value in x with `count` value greater
> than 0 and
> 2. Vector `eqzero` with value in x with `count` value equal to zero.
>
> Yielding
>
> > print(grzero)
> > [1] 0.80796 0.99998
> > print(eqzero)
> > [1] 0.49534 0.93970
>
> Regards,
> G.V.
>
It might be time to work your way through
'An Introduction to R'.
Anyway, here you want conditional extraction:
x[count > 0]
x[!(count > 0)] ##or equivalent
-Peter Ehlers
More information about the R-help
mailing list