Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.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 始终选择列表中的第一个元素 让我们考虑一下清单: x <- list(c(1), c(1,2), c(2,3,4)) x_R_List_Vector_Extract - Fatal编程技术网

R 始终选择列表中的第一个元素 让我们考虑一下清单: x <- list(c(1), c(1,2), c(2,3,4)) x

R 始终选择列表中的第一个元素 让我们考虑一下清单: x <- list(c(1), c(1,2), c(2,3,4)) x,r,list,vector,extract,R,List,Vector,Extract,这是否有效: lapply(x, '[', 1) [[1]] [1] 1 [[2]] [1] 1 [[3]] [1] 2 sapply(x, '[', 1) [1] 1 1 2 现在我们在谈! lapply(x, '[', 1) [[1]] [1] 1 [[2]] [1] 1 [[3]] [1] 2 sapply(x, '[', 1) [1] 1 1 2

这是否有效:

lapply(x, '[', 1)
[[1]]
[1] 1

[[2]]
[1] 1

[[3]]
[1] 2

sapply(x, '[', 1)
[1] 1 1 2
 

现在我们在谈!
lapply(x, '[', 1)
[[1]]
[1] 1

[[2]]
[1] 1

[[3]]
[1] 2

sapply(x, '[', 1)
[1] 1 1 2