[R] string split at xth position

Keith Weintraub kw1958 at gmail.com
Wed Mar 13 18:48:57 CET 2013


Here is another way

require(stringr)

aaa<-paste0("a", 1:20)
bbb<-paste0("b", 101:120)
ab<-paste0(aaa,bbb)
ab


ptrn<-"([ab][[:digit:]]*)"
unlist(str_extract_all(ab, ptrn))



> Hi,
> 
> I have a vector of strings like:
> c("a1b1","a2b2","a1b2") which I want to spilt into two parts like:
> c("a1","a2","a2") and c("b1","b2,"b2"). So there is
> always a first part with a+number and a second part with b+number.
> Unfortunately there is no separator I could use to directly split
> the vectors.. Any idea how to handle such cases?
> 
> /Johannes


--



More information about the R-help mailing list