[R] Removing variables

Chuck Cleland ccleland at optonline.net
Wed Aug 13 19:50:19 CEST 2003

Aurora Torrente wrote:
> Is there any way to remove at the same time several variables that share 
> a suffix, for example (similar to * or ?  in DOS) ?

   To remove objects sharing a suffix use something like:


   To remove variables sharing a suffix from a dataframe use 
something like:

newdata <- mydata[,-grep("SUFFIX$", names(mydata))]

   In both cases the $ metacharacter indicates that the literal 
characters are at the end of the string.

hope this helps,

Chuck Cleland

More information about the R-help mailing list