Hello, Could someone tell me, how can I select from a dataframe only those columns whose names contain a certain text? For example, if the column names are "Bond1.Creditclass","Bond1.Price","Bond2.Creditclass","Bond2.Price", how do I select only the columns corresponding to Bond1? Thanks a lot, Mihai [[alternative HTML version deleted]]
On 01/19/2010 01:22 PM, Mihai.Mirauta at bafin.de wrote:> > Hello, > > > Could someone tell me, how can I select from a dataframe only those columns whose names contain a certain text? > > For example, if the column names are "Bond1.Creditclass","Bond1.Price","Bond2.Creditclass","Bond2.Price", how do I select only the columns corresponding to Bond1? > > Thanks a lot, > > MihaiYou can do things like : > dataset[ , grepl( "^Bond1", names( dataset ) ) ] > dataset[ , substr( names( dataset ), 1, 5 ) == "Bond1" ] Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/KfKn : Rcpp 0.7.2 |- http://tr.im/JOlc : External pointers with Rcpp `- http://tr.im/JFqa : R Journal, Volume 1/2, December 2009
Mihai.Mirauta wrote:> > > Could someone tell me, how can I select from a dataframe only those > columns whose names contain a certain text? > > For example, if the column names are > "Bond1.Creditclass","Bond1.Price","Bond2.Creditclass","Bond2.Price", how > do I select only the columns corresponding to Bond1? >See Wacek's https://stat.ethz.ch/pipermail/r-help/2009-February/187462.html Dieter -- View this message in context: http://n4.nabble.com/Working-with-text-data-text-operators-tp1017490p1017837.html Sent from the R help mailing list archive at Nabble.com.