I think there should be a loop. Since the output matrix data is not all 2 columns. They are 2/3/4 cols.
And is there a way that I can get 3 matrices, not another list?
having the data.frames in a list is a convenient way to identify and refer to them, of course you could have them as independent data.frames in your environment (though I wouldnt myself)
but for that you should decide on how you will name them ?
The function I used needs the data to be a matrix, so the list type is not suitable. And I just don't want to generate hundreds of matrices manually.
Here is the error when I run my function:
Error: Not compatible with requested type: [type=list; target=double].
I used the code you shared: d1=map(a,~matrix(unlist(.))), and the result is close to what I want to get.
I'm sorry, I find your wording of your requirements hard to follow, and there are some inconsistencies you need to clarify.
e.g. you say you want to work with matrices, but then in your example code for data that you would like to automate, you were explicitly getting rid of matrices and making them dataframes (but naming them to yourselv as maxtrixn
also you are losing me when you say
d1=map(a,~matrix(unlist(.))),
this omits to set ncol's so presumably its a complete guess the matrix dimensions.
perhaps you should rather bind_cols as I suggested, but then cast the result to matrix
library(tidyverse)
(d1 <- map(
a,
~ as.matrix(bind_cols(.))
))
# if you want to get results with some function that requires matrices you can iterate also
d1[[3]] <- "not a matrix"
d1
(r1 <- map(
d1,
function(x) {
if (is.matrix(x))
return("happy")
"sad"
}
))