[R] concatenate vector after strsplit()
Robert Baer
rbaer at atsu.edu
Sun Feb 20 19:39:05 CET 2011
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 = sapply(as.data.frame(ls1)[1:4,], paste, collapse = "")
>> What I want to end up with is a vector that is the row-wise concatenation
>> of
>> the strings in each row of your matrix or each element of my original
>> list.
>
> Try this:
>
> sapply(ls1, function(x) paste(x[1:4], collapse = ""))
>
> or this:
>
> sapply(unname(as.data.frame(ls))[1:4,], paste, collapse = "")
>
> If you don't mind ugly names on the result the last one can be shortened
> to:
>
> sapply(as.data.frame(ls)[1:4,], paste, collapse = "")
>
> --
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com
>
More information about the R-help
mailing list