Search
Question: How to coerce CompressedIntegerList as vector?
0
gravatar for jian_liangli
2.2 years ago by
jian_liangli0 wrote:

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

ADD COMMENTlink modified 2.2 years ago • written 2.2 years ago by jian_liangli0
2
gravatar for Michael Lawrence
2.2 years ago by
United States
Michael Lawrence10k wrote:

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)

 

ADD COMMENTlink written 2.2 years ago by Michael Lawrence10k

Thanks, your answer helped.

ADD REPLYlink modified 2.2 years ago • written 2.2 years ago by jian_liangli0
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.2.0
Traffic: 376 users visited in the last hour