[R] how to delete specific rows in a data frame where the firstcolumn matches any string from a list

Doran, Harold HDoran at air.org
Fri Feb 6 16:33:36 CET 2009


Laura:

When posting to this list, it is best to provide a small example. This
will facilitate better help. Here is an example of what you want to do.

> mat <- matrix(rnorm(10), ncol=2)
> mat
           [,1]       [,2]
[1,] -0.1418628 -1.4559344
[2,]  0.4022863  1.4727494
[3,]  0.0158310  0.3471318
[4,]  0.3962089 -0.5179074
[5,]  1.8098082  0.7238309

### Remove rows 2 and 3
> (newMat <- mat[c(-2,-3),])
           [,1]       [,2]
[1,] -0.1418628 -1.4559344
[2,]  0.3962089 -0.5179074
[3,]  1.8098082  0.7238309 

I don't know what you mean about the second part (match a string on a
list). So, I didn't do anything with that

> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of Laura 
> Rodriguez Murillo
> Sent: Friday, February 06, 2009 10:26 AM
> To: r-help at r-project.org
> Subject: [R] how to delete specific rows in a data frame 
> where the firstcolumn matches any string from a list
> 
> Hi,
> 
> I'm new in the mailing list but I would appreciate if you 
> could help me with this:
> I have a big matrix from where I need to delete specific 
> rows. The second entry on these rows to delete should match 
> any string within a list (other file with just one column).
> Thank you so much!
> 
> Laura
> 
> ______________________________________________
> 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.
> 




More information about the R-help mailing list