On 07/09/2012 2:12 PM, David Romano wrote:
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").
sapply is the one that comes to mind:
> sapply(splitlist, "[[", 1)
[1] "a1" "a2"
> sapply(splitlist, "[[", 2)
[1] "b1" "b2"
______________________________________________
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.