Skip to content
Prev 86058 / 398528 Next

List Conversion

Hello,

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

Thanks.
Liz