[R] splitting character vectors into multiple vectors using strsplit

David Romano romanod at grinnell.edu
Fri Sep 7 20:12:15 CEST 2012


Hi folks,

Suppose I create the character vector charvec by

> charvec<-c("a1.b1","a2.b2")
> charvec
[1] "a1.b1" "a2.b2"

and then I use strsplit on charvec as follows:

> splitlist<-strsplit(charvec,split=".",fixed=TRUE)
> splitlist
[[1]]
[1] "a1" "b1"

[[2]]
[1] "a2" "b2"


I was wondering whether there is already a function which can extract
the "a" and "b" parts of the list splitlist; that is, that can return
the same vectors as those created by c("a1","a2") and c("b1","b2").

Thanks,
David Romano



More information about the R-help mailing list