[R] Deleting multiple rows based on a variable

Peter Alspach PAlspach at hortresearch.co.nz
Wed Feb 20 02:34:29 CET 2008


Kenneth

See %in%.  In your example:

Data2 <- subset(Data1, !Identity%in%c(1,2,3)) 

HTH ......

Peter Alspach


> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of Kenneth Takagi
> Sent: Wednesday, 20 February 2008 2:28 p.m.
> To: r-help at r-project.org
> Subject: [R] Deleting multiple rows based on a variable
> 
> Hello,
> 
>  
> 
> I have a dataset which consists of 9 columns (variables) and 
> 35 rows (observations).  I am doing a simple linear 
> regression of one variable on the other.  There are some 
> observations that are outliers and I would like to remove 
> them based on another variable (it's a unique, numeric 
> variable).  How do you tell R to remove multiple rows 
> (observations) based on a variable value?
> 
>  
> 
> For example, I am trying to remove observations that have 
> variable Identity = 1, 2, 3:
> 
>  
> 
> Data2<-subset(Data1, Identity!=c(1,2,3))> 
>  
> 
> This does not work.  It works if I do it one at a time, but 
> is very time consuming.  Is there a way to remove all desired 
> observations at once?
> 
>  
> 
> Thanks!   
> 
>  
> 
> Kenneth Takagi
> 
> kat215 at psu.edu
> 
>  
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

The contents of this e-mail are privileged and/or confidential to the named
 recipient and are not to be used by any other person and/or organisation.
 If you have received this e-mail in error, please notify the sender and delete
 all material pertaining to this e-mail.



More information about the R-help mailing list