Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

convert list to vector in r

I have a list object of NULL and I would like to convert it as vector NULL. How to get around with it? Many thanks in advance.

myList <- list('A' = NULL, 'B'= NULL, 'C'= NULL); myList 

Expected Answer

 A <- B <- C <- NULL

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The input already is a vector of NULL values

is.vector(myList)
## [1] TRUE

sapply(myList, is.null)
##    A    B    C 
## TRUE TRUE TRUE 

so we assume that the question is asking to create objects A, B and C in the global environment with the values that the components of those names have in myList. (If the current environment could be different from the global environment and you wanted them assigned into the current environment then use environment() as the second argument, instead.)

 list2env(myList, .GlobalEnv)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading