Sarah Henderson wrote:
> 
> 
> I think my Python brain is missing something crucial about string
> operations in R, but I cannot figure this out.
> 
> I have a large data frame with several groups of similar variables.
> Similar variables are named according to their group, and I am now
> writing a function to check correlations within groups.  I want to
> subset the data frame by partial variable name, something along the
> lines of this:
> 

With thanks to Peter Dalgaard, who sent me this 10 years ago at my first
posting. You can do it in one line though, and use <- to be a real fReak.

d = data.frame(xxx1=1:10,xx2=1:10,yy2=1:10,axx=1:10)
selcols = grep("^xx", names(d))
d[,selcols]

Dieter

-- 
View this message in context: 
http://n4.nabble.com/Sub-setting-a-data-frame-by-partial-column-names-tp1577672p1577699.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@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.

Reply via email to