Array in R using lists

I have two lists created with list3 = list(1,2,3,4)and list4 = list(5,6,7,8).

I create an array like:

myarray <- array(list3, list4)

I get the output as an array 56 * 5 * 6. It is impossible to understand why this is happening?

+4
source share
2 answers

Maybe something like this

list3 <- list(1,2,3,4)
list4 <- list(5,6,7,8)
listall <- append(list3, list4)
array(listall, c(2, length(listall) / 2))

exits

     [,1] [,2] [,3] [,4]
[1,] 1    3    5    7   
[2,] 2    4    6    8   

For this reason you can look in the docs

?array

Usage
array(data = NA, dim = length(data), dimnames = NULL)
...

So, you passed your second list ( list4in your example) as a parameterdim

+4
source

Disable and merge like this:

c(unlist(list3), unlist(list4))
+2
source

Source: https://habr.com/ru/post/1654659/


All Articles