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 =
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
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,
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
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
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
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
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.
8 matches
Mail list logo