[R] Sub-setting a data frame by partial column names?

Sarah Henderson sarah.b.henderson at gmail.com
Thu Mar 4 07:51:03 CET 2010


Hi all --

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:

partialName <- "XXX"
subsetData <- bigData[, partialName in colnames(bigData)]

Where bigData might have 10 columns named "XXX1", "XXX2" etc.

Many thanks for any thoughts,

Sarah



More information about the R-help mailing list