[R] Deleting rows with special character

arun smartpink111 at yahoo.com
Fri Nov 16 15:36:20 CET 2012


HI,

Not sure how your dataset looks like:
If it is like this:

set.seed(18)
mat1<-matrix(sample(LETTERS[1:3],54,replace=TRUE),ncol=3)
 mat1[apply(mat1,1,function(x) all(x=="A")),]
#[1] "A" "A" "A"
which(apply(mat1,1,function(x) all(x=="A")) )
#[1] 16
A.K.






----- Original Message -----
From: Peter Kupfer <peter.kupfer at me.com>
To: "r-help at r-project.org" <r-help at r-project.org>
Cc: 
Sent: Friday, November 16, 2012 9:04 AM
Subject: [R] Deleting rows with special character

Dear all,
maybe a simple problem but I found no solution for my problem.
I have a matrix Y with 23 000 rows and 220 colums. The entries are "A", "B" or "C".
I want to extract all rows (as a matrix ) of the matrix Y where all entries of a row are (for example) "A".
Is there any solution? I tried the stringr- package but i doesn't work out.
All the best and thanks!
Peter

______________________________________________
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