[R] calasification table under conditions

Steve Lianoglou mailinglist.honeypot at gmail.com
Thu Aug 6 16:10:04 CEST 2009


Hi,

On Aug 6, 2009, at 9:26 AM, Inchallah Yarab wrote:

> hi,
>
> i have a file with 49000 lines i want to do a classification in two  
> tables
> suppose data <- read.csv2("c:/total.csv", sep=",")
> if the second colonne contains ( A,B,C,D)------------> tab1
> if the second colonne contains ( E,F,G,H)------------> tab2
>
> How can do this ?


One easy way is to read the data into a table first, then split it in  
two after loading. I'm going to take you literally when you say you  
want the column to contain, rather than the column be equal to, so  
I'll use some regular expression mojo:

dat <- read.csv2(...)
tab1 <- dat[grep('[ABCD]', dat[,2], ]
tab2 <- dat[grep('[EFGH]', dat[,2]), ]

optionally rm the dat variable if you're hurting for RAM.

-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
   |  Memorial Sloan-Kettering Cancer Center
   |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact




More information about the R-help mailing list