Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.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
如果元素在R中是多维的,如何展平所有(嵌套)元素?_R_List - Fatal编程技术网

如果元素在R中是多维的,如何展平所有(嵌套)元素?

如果元素在R中是多维的,如何展平所有(嵌套)元素?,r,list,R,List,假设我有以下数据: data <- list(arr = c(2, 2), ab = list(x = c(4, 4), e = list(f = c(1, 2), ff = 1:3, dd = data.frame(c = 1:3, d = 2:4)))) 我的尝试: > list(arr = c(2, 2), ab.x = c(4, 4), ab.e.f = c(1, 2), + ab.e.ff = c(1, 2, 3)

假设我有以下数据:

data <- list(arr = c(2, 2), ab = list(x = c(4, 4), 
             e = list(f = c(1, 2), ff = 1:3, dd = data.frame(c = 1:3, d = 2:4))))
我的尝试:

>   list(arr = c(2, 2), ab.x = c(4, 4), ab.e.f = c(1, 2), 
+             ab.e.ff = c(1, 2, 3), ab.e.dd.c = 1:3, ab.e.dd.d = 2:4)
$arr
[1] 2 2

$ab.x
[1] 4 4

$ab.e.f
[1] 1 2

$ab.e.ff
[1] 1 2 3

$ab.e.dd.c
[1] 1 2 3

$ab.e.dd.d
[1] 2 3 4
(一)

(二)


继续我相信这肯定会有帮助-
rlist::list.flatten(数据)
,这里已经解释过的方法我相信这肯定会有帮助-
rlist::list.flatten(数据)
,这里已经解释过的方法
unlist(data, recursive = FALSE)
continue <- TRUE
lst <- list()
nr <- 1
while(continue){
  lst[[nr]] <- data
  data <- unlist(lst[[nr]], recursive = FALSE)
  continue <- !identical(lst[[nr]], data)
  nr <- nr + 1
}
lst[nr - 2]