Re: [R] splitting character vectors into multiple vectors using strsplit

2012-11-02 Thread arun
PM Subject: Re: [R] splitting character vectors into multiple vectors using strsplit Hi again, I just wanted to thank folks for their suggestions; they led me to understand the *apply family a little better, and to realize the issue was really a question of how to convert a list of equal length vec

Re: [R] splitting character vectors into multiple vectors using strsplit

2012-11-02 Thread R. Michael Weylandt
On Fri, Nov 2, 2012 at 7:49 PM, David Romano wrote: > I don't know if R has the equivalent of an identity > function, but the following solution accomplishes this: > >> splitvectors <- sapply(splitlist, function(x) x) Indeed it does, called, not surprisingly, "identity." You managed to guess the

Re: [R] splitting character vectors into multiple vectors using strsplit

2012-11-02 Thread David Romano
Hi again, I just wanted to thank folks for their suggestions; they led me to understand the *apply family a little better, and to realize the issue was really a question of how to convert a list of equal length vectors into a matrix. In this case sapply only needs to be asked to identify these ve

Re: [R] splitting character vectors into multiple vectors using strsplit

2012-09-07 Thread arun
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 To: r-help@r-project.org Cc: Sent: Friday, September 7, 2012 2:12 PM Subject: [R] splitting charact

Re: [R] splitting character vectors into multiple vectors using strsplit

2012-09-07 Thread arun
Hi, You can also try this: unlist(lapply(splitlist,head,1)) #[1] "a1" "a2"  unlist(lapply(splitlist,tail,1)) #[1] "b1" "b2" A.K. From: David Romano To: r-help@r-project.org Sent: Friday, September 7, 2012 2:12 PM Subject: [R] splitting character vectors in

Re: [R] splitting character vectors into multiple vectors using strsplit

2012-09-07 Thread Richard M. Heiberger
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

Re: [R] splitting character vectors into multiple vectors using strsplit

2012-09-07 Thread Duncan Murdoch
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"