If you know that there are exactly the same number of items in each string, then something simpler can be constructed.
> matrix(unlist(splitlist), length(splitlist[[1]]), length(splitlist)) [,1] [,2] [1,] "a1" "a2" [2,] "b1" "b2" > The rows above are what you are looking for. If you intend to treat these as columns of a data array, then you might instead want > matrix(unlist(splitlist), length(splitlist[[1]]), length(splitlist), byrow=TRUE) [,1] [,2] [1,] "a1" "b1" [2,] "a2" "b2" > and here the columns are what you are looking for. Rich On Fri, Sep 7, 2012 at 2:20 PM, Duncan Murdoch <murdoch.dun...@gmail.com>wrote: > 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<https://stat.ethz.ch/mailman/listinfo/r-help> > PLEASE do read the posting guide http://www.R-project.org/** > posting-guide.html <http://www.R-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ 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.