[R] R equivalent of linux "cut", "paste", and "grep" ?

Greg Snow Greg.Snow at imail.org
Thu Feb 14 17:37:14 CET 2008


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



More information about the R-help mailing list