Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 将三维阵列转换为列表列表_Arrays_R_List - Fatal编程技术网

Arrays 将三维阵列转换为列表列表

Arrays 将三维阵列转换为列表列表,arrays,r,list,Arrays,R,List,我有一个3D阵列,例如: arr <- array(dim = c(10, 4, 3), data = rep(rnorm(10), 120)) dimnames(arr) <- list(itr = NULL, chain = c("c1","c2","c3","c4"), param = c("alpha","beta","gamma")) arr这可能适合您 a <- apply(arr, 3, function(x) c(as.data.frame(x))) 对我有

我有一个3D阵列,例如:

arr <- array(dim = c(10, 4, 3), data = rep(rnorm(10), 120))
dimnames(arr) <- list(itr = NULL, chain = c("c1","c2","c3","c4"), param = c("alpha","beta","gamma"))

arr这可能适合您

a <- apply(arr, 3, function(x) c(as.data.frame(x)))

对我有用。我怀疑在某些情况下,
as.data.frame
可能需要一段时间,但这似乎并不重要。是的,我也很想知道,但它很好地保留了所有的名称
lapply(a, names)
# $alpha
# [1] "c1" "c2" "c3" "c4"
#
# $beta
# [1] "c1" "c2" "c3" "c4"
#
# $gamma
# [1] "c1" "c2" "c3" "c4"
unique(rapply(a, length))
# [1] 10