[R] subsetting data file by intoducing a second file
Ozgul Inceoglu
Ozgul.Inceoglu at ulb.ac.be
Tue Feb 12 15:29:27 CET 2013
Hello,
I have a very data matrix and I have a file which has the names that I need to subset. However I cannot manage to subset the main file. ANy idea?
bg <- read.table (file.choose(), header=T, row.names)
bg
Otu00022 Otu00029 Otu00039 Otu00042 Otu00101 Otu00105 Otu00125 Otu00131 Otu00137 Otu00155 Otu00158 Otu00172 Otu00181 Otu00185 Otu00190 Otu00209 Otu00218
Gi20Jun11 0.001217 0 0.001217 0 0.000000 0 0 0 0.001217 0 0 0 0 0 0.001217 0 0.001217
Gi40Jun11 0.000000 0 0.000000 0 0.000000 0 0 0 0.000000 0 0 0 0 0 0.000000 0 0.000000
Gi425Jun11 0.000000 0 0.000000 0 0.000000 0 0 0 0.000000 0 0 0 0 0 0.000000 0 0.000000
Gi45Jun11 0.000000 0 0.000000 0 0.001513 0 0 0 0.000000 0 0 0 0 0 0.000000 0 0.000000
Gi475Jun11 0.000000 0 0.000000 0 0.000000 0 0 0 0.000000 0 0 0 0 0 0.000000 0 0.000000
Gi50Jun11 0.000000 0 0.000000 0 0.000000 0 0 0 0.000000 0 0 0 0 0 0.000000 0 0.000000
...
#second file which has the names that I want to subset
c_bg
[,1]
[1,] "Otu0128"
[2,] "Otu0218"
[3,] "Otu0034"
[4,] "Otu0257"
[5,] "Otu0212"
[6,] "Otu0279"
[7,] "Otu0318"
[8,] "Otu0266"
[9,] "Otu0056"
...
#by using the c_bg name file, I would like to subset bg file
g1<-subset(bg,colnames(bg) %in% (c_bg))
# this returns me the all the column names in bg file.
Thank you,
Ö
More information about the R-help
mailing list