An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100119/d0a9730e/attachment.pl>
Working with text data/text operators
3 messages · Mihai.Mirauta at bafin.de, Romain Francois, Dieter Menne
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, Mihai
You 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.