Hi, What functions should I use in order to perform the following steps: 1) Load a particular column (e.g., column 5) from a csv file 2) Append the column 5 to another csv file 3) select those rows that match specific keywords in column 5 [[alternative HTML version deleted]]
Romain Francois
2008-Feb-14 09:57 UTC
[R] R equivalent of linux "cut", "paste", and "grep" ?
Hi, If you are on a linux system, you can use these linux commands through pipe. Otherwise : - perl would do a great job on this. - if you are familiar enough with SQL syntax, you can use the development version of the sqldf package to work on csv files as if they were database tables. See example 8 in http://code.google.com/p/sqldf/ Cheers, Romain Ng Stanley wrote:> Hi, > > What functions should I use in order to perform the following steps: > > 1) Load a particular column (e.g., column 5) from a csv file > 2) Append the column 5 to another csv file > 3) select those rows that match specific keywords in column 5 >-- Mango Solutions data analysis that delivers Introduction to R training course :: London :: 06-07 March 2008 http://www.mango-solutions.com/services/rtraining/r_intro.html
Depending on what your final goal is, there may be a better approach, but to do as you state below, here is one set of options: 1) use read.csv (or read.table) and use the colClasses argument to specify keeping only column 5 2) use cbind to bind column 5 (now a data.frame) to another data.frame (possibly read in using read.csv), this assumes that the row order matches, merge is a possibility if they don't match. 3) use the subset command to select the rows, use the %in% operator to compare col 5 to your list of desired values. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org (801) 408-8111> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Ng Stanley > Sent: Thursday, February 14, 2008 1:03 AM > To: r-help > Subject: [R] R equivalent of linux "cut", "paste", and "grep" ? > > Hi, > > What functions should I use in order to perform the following steps: > > 1) Load a particular column (e.g., column 5) from a csv file > 2) Append the column 5 to another csv file > 3) select those rows that match specific keywords in column 5 > > [[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. >