Reputation: 1991
I have two lists created using list3 = list(1,2,3,4)
and list4 = list(5,6,7,8)
.
I create an array as :
myarray <- array(list3, list4)
I get an output as a 56*5*6 array. Unable to understand, why is it happening so ?
Upvotes: 4
Views: 72
Reputation: 35338
Maybe something like that
list3 <- list(1,2,3,4)
list4 <- list(5,6,7,8)
listall <- append(list3, list4)
array(listall, c(2, length(listall) / 2))
outputs
[,1] [,2] [,3] [,4]
[1,] 1 3 5 7
[2,] 2 4 6 8
For the reason behind your output have a look into the docs
?array
Usage
array(data = NA, dim = length(data), dimnames = NULL)
...
So you passed your second list (list4
in your sample) as the dim
parameter
Upvotes: 4