[R] List Conversion

Liz Dem liz392 at mail.com
Thu Feb 9 04:21:41 CET 2006


Hello,

I have a list (mode and class are list) in R that is many elements long and of the form:
>length(list)
[1] 5778
>list[1:4]
$ID1
[1] "num1"
$ID2
[1] "num2" "num3"
$ID3
[1] "num4"
$ID4
[1] NA

I'd like to convert the $ID2 value to be in one element rather than in two.  It shows up as c(\"num2\", \"num3\") if I try to use paste(list[2], collapse="").  I need to do this over the length of the entire list, however list2 <- apply(list, 1, paste, collapse="") tells me 'Error in apply : dim(X) must have a positive length'.  dim(list) does not have a positive length, which I think is due to the fact that it's a list and not a matrix or data frame.  

What I want to get is:
>list[1:4]
$ID1
[1] "num1"
$ID2
[1] "num2 num3"
$ID3
[1] "num4"
$ID4
[1] NA

Thanks.
Liz

-- 
___________________________________________________
Play 100s of games for FREE! http://games.mail.com/




More information about the R-help mailing list