splitting by the last occurance of a dot
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