Re: [R] concatenate vector after strsplit()

2011-02-20 Thread Robert Baer
Thanks Gabor. Your suggestions work as well and have been helpful in my understanding, I can't use any excuse of not knowing about "]" in this case! Rob fil3 = sapply(ls1, function(x) paste(x[1:4], collapse = "")) fil4 = sapply(unname(as.data.frame(ls1))[1:4,], paste, collapse = "") fil5 =

Re: [R] concatenate vector after strsplit()

2011-02-20 Thread Robert Baer
Thanks Jorge and David. Both worked. Looks like I have to read more on "[" as an extractor function for lists. do.call() is also on my list of "low level magic' I don't understand.Appreciate the help! fil1 = do.call(c, lapply(lapply(ls1, "[", 1:4), paste, sep = "", collapse = "-")) fil

Re: [R] concatenate vector after strsplit()

2011-02-20 Thread Gabor Grothendieck
On Sun, Feb 20, 2011 at 12:43 PM, Robert Baer wrote: >> You might try >> >> do.call(rbind, lapply(yourlist, "[", 1:4)) > > Thanks, Jorge, but when I tried this I simply got a matrix of character > strings rather than my original list of character strings as in: >> >> m = do.call(rbind, lapply(ls,

Re: [R] concatenate vector after strsplit()

2011-02-20 Thread David Winsemius
On Feb 20, 2011, at 12:49 PM, David Winsemius wrote: On Feb 20, 2011, at 11:13 AM, Robert Baer wrote: ls is a list of character vectors created by strsplit() I want to concatenate the 1st 4 character elements of each list item as a new vector called file. I admit to being confused about

Re: [R] concatenate vector after strsplit()

2011-02-20 Thread David Winsemius
On Feb 20, 2011, at 11:13 AM, Robert Baer wrote: ls is a list of character vectors created by strsplit() I want to concatenate the 1st 4 character elements of each list item as a new vector called file. I admit to being confused about list syntax even after numerous readings. Here's wh

Re: [R] concatenate vector after strsplit()

2011-02-20 Thread Robert Baer
You might try do.call(rbind, lapply(yourlist, "[", 1:4)) Thanks, Jorge, but when I tried this I simply got a matrix of character strings rather than my original list of character strings as in: m = do.call(rbind, lapply(ls, "[", 1:4)) m [,1] [,2] [,3] [,4] [1,] "Focused" "10k" "A12

Re: [R] concatenate vector after strsplit()

2011-02-20 Thread Jorge Ivan Velez
Hi Robert, You might try do.call(rbind, lapply(yourlist, "[", 1:4)) and then write the resulting file using write.table(...). Best, Jorge On Sun, Feb 20, 2011 at 11:13 AM, Robert Baer <> wrote: > ls is a list of character vectors created by strsplit() > > I want to concatenate the 1st 4 char

[R] concatenate vector after strsplit()

2011-02-20 Thread Robert Baer
ls is a list of character vectors created by strsplit() I want to concatenate the 1st 4 character elements of each list item as a new vector called file. I admit to being confused about list syntax even after numerous readings. Here's what I tried: ls <- list(c("Focused", "10k", "A12", "t04.