Hi all, I want to select all variables in the data.frame with a name that includes are certain string. Something like the following: merge3[,names(merge3) %in% c("Email","Email.x")] But there are too many variations on the Email variable names to list them all. Can anyone advise? Thanks! Dan
Check the string matching functions, e.g. grepl(). -pd> On 16 Apr 2016, at 15:18 , Dan Abner <dan.abner99 at gmail.com> wrote: > > Hi all, > > I want to select all variables in the data.frame with a name that > includes are certain string. Something like the following: > > merge3[,names(merge3) %in% c("Email","Email.x")] > > But there are too many variations on the Email variable names to list them all. > > Can anyone advise? > > Thanks! > > Dan > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.-- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
> On Apr 16, 2016, at 6:30 AM, peter dalgaard <pdalgd at gmail.com> wrote: > > Check the string matching functions, e.g. grepl().Concretely: merge3[, grepl( "Email|Email\\.x", names(merge3) ) ] # since "." is special in grepisch patterns. Which admittedly is a bit redundant since any character value that included `Email.x" would already have been picked up by the "Email" alternative.> > -pd > >> On 16 Apr 2016, at 15:18 , Dan Abner <dan.abner99 at gmail.com> wrote: >> >> Hi all, >> >> I want to select all variables in the data.frame with a name that >> includes are certain string. Something like the following: >> >> merge3[,names(merge3) %in% c("Email","Email.x")] >> >> But there are too many variations on the Email variable names to list them all. >> >> Can anyone advise? >> >> Thanks! >> >> Dan >>>David Winsemius Alameda, CA, USA