The vector is like this:
c(1,2,3) #[1] 1 2 3
I need something like this:
list(1,2,3) #[[1]] #[1] 1 # #[[2]] #[1] 2 # #[[3]] #[1] 3
I tried this:
list(c(1,2,3)) #[[1]] #[1] 1 2 3
In order to convert a vector to a list, R provides us with unlist() function that converts the list into a vector in R. The unlist() function dissolves the list structure fed to it as arguments i.e. it converts the multi-dimensional schema into a a single dimensional schema. use.
list() Function. as. list() function in R Programming Language is used to convert an object to a list.
You can stick a vector (a restricted structure where all components have to be of the same type) into a list (unrestricted). But you cannot do the reverse. Use lists of lists of lists ... and then use lapply et al to extract.
Simple, just do this:
as.list(c(1,2,3))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With