hi, everyone: i have a data frame with one single character column as followings: DS_xxx_yyy_24hr_zzz_1 DS_xxx_yyy_24hr_zzz_2 DS_xxx_yyy_24hr_zzz_3 DS_xxx_yyy_24hr_zzz_4 DS_xxx_yyy_24hr_zzz_1 DS_xxx_yyy_24hr_zzz_2 DS_xxx_yyy_24hr_zzz_3 DS_xxx_yyy_24hr_zzz_4 DS_xxx_yyy_24hr_zzz_1 i need to parse out the time part like the followings: name time DS_xxx_yyy_24hr_zzz_1 24hr DS_xxx_yyy_24hr_zzz_2 24hr DS_xxx_yyy_24hr_zzz_3 24hr DS_xxx_yyy_24hr_zzz_4 24hr DS_xxx_yyy_24hr_zzz_1 24hr DS_xxx_yyy_24hr_zzz_2 24hr DS_xxx_yyy_24hr_zzz_3 24hr DS_xxx_yyy_24hr_zzz_4 24hr DS_xxx_yyy_24hr_zzz_1 24hr what function should I look at? i have tried: strsplit(data, '_') and get a giant list which is not what i need. thanks in advance -- View this message in context: http://r.789695.n4.nabble.com/how-to-parse-out-string-separated-by-special-character-tp2246301p2246301.html Sent from the R help mailing list archive at Nabble.com.
Henrique Dallazuanna
2010-Jun-07 20:58 UTC
[R] how to parse out string separated by special character
Try this: gsub(".*_(.*)_.*_.*", "\\1", s) On Mon, Jun 7, 2010 at 2:21 PM, xin wei <xinwei@stat.psu.edu> wrote:> > hi, everyone: > i have a data frame with one single character column as followings: > DS_xxx_yyy_24hr_zzz_1 > DS_xxx_yyy_24hr_zzz_2 > DS_xxx_yyy_24hr_zzz_3 > DS_xxx_yyy_24hr_zzz_4 > DS_xxx_yyy_24hr_zzz_1 > DS_xxx_yyy_24hr_zzz_2 > DS_xxx_yyy_24hr_zzz_3 > DS_xxx_yyy_24hr_zzz_4 > DS_xxx_yyy_24hr_zzz_1 > > i need to parse out the time part like the followings: > name time > DS_xxx_yyy_24hr_zzz_1 24hr > DS_xxx_yyy_24hr_zzz_2 24hr > DS_xxx_yyy_24hr_zzz_3 24hr > DS_xxx_yyy_24hr_zzz_4 24hr > DS_xxx_yyy_24hr_zzz_1 24hr > DS_xxx_yyy_24hr_zzz_2 24hr > DS_xxx_yyy_24hr_zzz_3 24hr > DS_xxx_yyy_24hr_zzz_4 24hr > DS_xxx_yyy_24hr_zzz_1 24hr > > what function should I look at? > i have tried: strsplit(data, '_') and get a giant list which is not what i > need. > > thanks in advance > > -- > View this message in context: > http://r.789695.n4.nabble.com/how-to-parse-out-string-separated-by-special-character-tp2246301p2246301.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > 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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
Greg Snow
2010-Jun-07 20:59 UTC
[R] how to parse out string separated by special character
Look at the strapply function in the gsubfn package. It may do what you want. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of xin wei > Sent: Monday, June 07, 2010 11:21 AM > To: r-help at r-project.org > Subject: [R] how to parse out string separated by special character > > > hi, everyone: > i have a data frame with one single character column as followings: > DS_xxx_yyy_24hr_zzz_1 > DS_xxx_yyy_24hr_zzz_2 > DS_xxx_yyy_24hr_zzz_3 > DS_xxx_yyy_24hr_zzz_4 > DS_xxx_yyy_24hr_zzz_1 > DS_xxx_yyy_24hr_zzz_2 > DS_xxx_yyy_24hr_zzz_3 > DS_xxx_yyy_24hr_zzz_4 > DS_xxx_yyy_24hr_zzz_1 > > i need to parse out the time part like the followings: > name time > DS_xxx_yyy_24hr_zzz_1 24hr > DS_xxx_yyy_24hr_zzz_2 24hr > DS_xxx_yyy_24hr_zzz_3 24hr > DS_xxx_yyy_24hr_zzz_4 24hr > DS_xxx_yyy_24hr_zzz_1 24hr > DS_xxx_yyy_24hr_zzz_2 24hr > DS_xxx_yyy_24hr_zzz_3 24hr > DS_xxx_yyy_24hr_zzz_4 24hr > DS_xxx_yyy_24hr_zzz_1 24hr > > what function should I look at? > i have tried: strsplit(data, '_') and get a giant list which is not > what i > need. > > thanks in advance > > -- > View this message in context: http://r.789695.n4.nabble.com/how-to- > parse-out-string-separated-by-special-character-tp2246301p2246301.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > 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.