[R] dataframe

arun smartpink111 at yahoo.com
Tue Apr 29 17:59:43 CEST 2014


Hi,

It is better to show example data using ?dput().

dat <- structure(list(row.names = 1:4, XYZ = c("sample", "sample2", 
"sample3", "sample4"), `000_001` = c("sample", "Au5", "C", "C"
), `000_002` = c("sample", "Au32", "C", "Au4"), `000_003` = c("sample", 
"Au5", "A", "AC")), .Names = c("row.names", "XYZ", "000_001", 
"000_002", "000_003"), class = "data.frame", row.names = c(NA, 
-4L))


dat[,intersect(grep("Au5", dat), grep("\\bC\\b",dat)),drop=FALSE]
#  000_001
#1  sample
#2     Au5
#3       C
#4       C

A.K.




On Tuesday, April 29, 2014 9:45 AM, "pascalbells at libero.it" <pascalbells at libero.it> wrote:
Hello, 
thank you for accepting me into the list.

I have the following dataframe:

   row.names  X           Y       Z     000_001  000_002  000_003
1                    sample                     sample    sample     sample
2                    sample2                   Au5         Au32       Au5
3                    sample3                   C              C             C
4                    ...........  
..
..n                    ............                    ....            .......         ............


I would like to select al the columns that have Au5 and C.
thank you in advance for your help,
james


    [[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.




More information about the R-help mailing list