[R] splitting character vectors into multiple vectors using strsplit
arun
smartpink111 at yahoo.com
Fri Sep 7 22:22:37 CEST 2012
Hi,
You can also try this:
sapply(lapply(splitlist,rle),`[[`,2)[1,]
#[1] "a1" "a2"
sapply(lapply(splitlist,rle),`[[`,2)[2,]
#[1] "b1" "b2"
A.K.
----- Original Message -----
From: David Romano <romanod at grinnell.edu>
To: r-help at r-project.org
Cc:
Sent: Friday, September 7, 2012 2:12 PM
Subject: [R] splitting character vectors into multiple vectors using strsplit
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
______________________________________________
R-help at 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.
More information about the R-help
mailing list