How to coerce CompressedIntegerList as vector?
1
0
Entering edit mode
@jian_liangli-11294
Last seen 4.8 years ago

Hi,

I have a list where each list element is IntegerList, I want to coerce IntegerList object to vector. I tried of using as.vector function, but it is still not simplified as I expected. How can make this happen? Any idea?

I tried as follow, but output is not what I expected:

lapply(myList, as.vector)

# mini example:

myList <- list(
a=IntegerList(1,2,3,4),
b=IntegerList(3,4,integer(0),integer(0)),
c=IntegerList(1,4,6,7)
)


# desired output:

desired_output <- list(
a=c(1,2,3,4),
b=c(3,4,0,0),
c=c(1,4,6,7)
)

How can I achieve me desired output? Can anyone propose possible idea to make this coercion happen easily? Thanks

s4 coercion iranges integerlist • 627 views
2
Entering edit mode
@michael-lawrence-3846
Last seen 6 weeks ago
United States

as.vector() behaves the same way on Lists as it does on ordinary lists.

Are you sure that each IntegerList has zero or one elements? If so, you can use drop(), as in:

lapply(myList, drop)

0
Entering edit mode