[R] removal of an element from a vector

Kort, Eric Eric.Kort at vai.org
Wed Jan 4 14:29:13 CET 2006


Gynmeerut asks...
> Dear All,
>   I have some problem in R which I'm explaining using an example:
> x<-(120,235,172,95,175,200,233,142)
> i want to remove the elements which are lesser than 100 and as a
result i
> want two vectors
> 
> y<-(containing elements <100)
> z<-(remaining elements)

x<-c(120,235,172,95,175,200,233,142)
y <- x[which(x < 100)]
z <- x[which(x >= 100)]

> Moreover if I wish to use two different programs for vectors y and z.
> which command shall I use(will IF-ELSE  work ?)

This part of the question I do not quite understand.  Now that you have
y and z, you can do whatever you like with them.  But R certainly does
have conditional control statements (if/else) as described in An
Introduction to R. 

-Eric

> 
> 
> 
> Thanks and regards,
> 
> GS
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-
> guide.html
This email message, including any attachments, is for the so...{{dropped}}




More information about the R-help mailing list