An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111108/8941436a/attachment.pl>
splitting by the last occurance of a dot
5 messages · Ashim Kapoor, Gabor Grothendieck
On Tue, Nov 8, 2011 at 6:06 AM, Ashim Kapoor <ashimkapoor at gmail.com> wrote:
Dear R-helpers, I want to split the following vector into 2 vectors by the last occurance of a .
dput(rownames(sensext))
c("pat", "cash_bank_bal", "invest_abroad", "pat.1", "cash_bank_bal.1",
"invest_abroad.1", "pat.2", "cash_bank_bal.2", "invest_abroad.2",
"pat.3", "cash_bank_bal.3", "invest_abroad.3", "pat.4", "cash_bank_bal.4",
"invest_abroad.4", "Market.Capitalisation", "Market.Capitalisation.1",
"Market.Capitalisation.2", "Market.Capitalisation.3",
"Market.Capitalisation.4"
)
My attempt :
I tried strsplit(rownames(sensext),"\\.") but that splits it into 3 parts
sometimes,the logic of which I can see,since there are 2 dots sometimes.
Can someone tell me how to split this ?
Assuming we want to split off the number at the end try this which splits on those dots which are followed by a digit: strsplit(r, "\\.(?=\\d)", perl = TRUE)
Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111108/550ce013/attachment.pl>
On Tue, Nov 8, 2011 at 6:48 AM, Ashim Kapoor <ashimkapoor at gmail.com> wrote:
Assuming we want to split off the number at the end try this which splits on those dots which are followed by a digit: strsplit(r, "\\.(?=\\d)", perl = TRUE)
Dear Gabor, Thank you? very much. That works very well. I don't completely understand it though. A few words on what the (?=\\d) is doing would be nice.
See the info on zero width lookahead assertions on the ?regex page.
Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111108/0c00b40f/attachment.pl>