> str(mylist)
List of 50
$ : logi [1:14] 0.2 0.3 0.2 ...
$ : logi [1:14] 0.1 0.3 0.6 ...
$ : logi [1:14] 0.2 0.9 0.1 ...
I want to convert (or write out) mylist
to 14 matrices with dim 5 10
or one array with dim 5 10 14
Example data:
mylist <- lapply(1:50, function(i) sample((1:14)/10, 14, repl=TRUE))
To convert R List to Matrix, use the matrix() function and pass the unlist(list) as an argument. The unlist() method in R simplifies it to produce a vector that contains all the atomic components which occur in list data.
The best and easiest way to convert a List into an Array in Java is to use the . toArray() method. Likewise, we can convert back a List to Array using the Arrays. asList() method.
The key difference between tables and matrices is that tables can include only row groups, where as matrices have row groups and column groups. Lists are a little different. They support a free-layout that and can include multiple peer tables or matrices, each using data from a different dataset.
This will produce the desired array (with NAs for the nonnumeric values):
array(as.numeric(unlist(mylist)), dim=c(14, 5, 10))
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