Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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 从R中的列表中获取元素中的元素_Arrays_R_Lapply - Fatal编程技术网

Arrays 从R中的列表中获取元素中的元素

Arrays 从R中的列表中获取元素中的元素,arrays,r,lapply,Arrays,R,Lapply,我想使用lappy函数从列表中提取嵌入元素中的元素。原始列表包含恰好是数组的元素,R包georoph中的gpagen函数会弹出一个新的列表,其中每个元素都包含一个嵌入其中的元素,我想获取这些嵌入元素并将它们定向到一个新对象 输入示例: >unaligned_coords $individual1 , , rep1 [,1] [,2] [,3] [1,] 58.81923 2.452332 273.2005 [2,] 68.24838 -4.29848

我想使用lappy函数从列表中提取嵌入元素中的元素。原始列表包含恰好是数组的元素,R包georoph中的gpagen函数会弹出一个新的列表,其中每个元素都包含一个嵌入其中的元素,我想获取这些嵌入元素并将它们定向到一个新对象

输入示例:

>unaligned_coords
$individual1
, , rep1

         [,1]      [,2]     [,3]
[1,] 58.81923  2.452332 273.2005
[2,] 68.24838 -4.298481 271.2884
[3,] 69.58006 -1.127088 270.0316

, , rep2

         [,1]      [,2]     [,3]
[1,] 58.82360  2.485687 273.1929
[2,] 68.14501 -4.233420 271.3564
[3,] 69.02335 -0.875766 270.4671

$individual2
, , rep1

         [,1]       [,2]     [,3]
[1,] 58.64723 -1.7827113 271.4866
[2,] 69.53938 -7.0807052 274.4347
[3,] 72.35068  0.1114307 272.1112

, , rep2

         [,1]       [,2]     [,3]
[1,] 58.63091 -1.7735939 271.4576
[2,] 68.78160 -6.9430161 274.1252
[3,] 73.07706  0.3313497 272.1727

...
aligned_coords <- lapply(unaligned_coords, gpagen)
>aligned_coords
$individual1
 , , rep1

            [,1]         [,2]         [,3]
 [1,] -0.1838745 -0.002361134  0.001343360
 [2,]  0.1717784 -0.065992358 -0.003245113
 [3,]  0.1701612  0.025533125 -0.068783434

 , , rep2

            [,1]        [,2]          [,3]
 [1,] -0.1844239  0.00147890  0.0001282347
 [2,]  0.1846240 -0.07485290 -0.0031490047
 [3,]  0.1681969  0.02331805 -0.0627923402

$individual2
 , , rep1

            [,1]         [,2]        [,3]
 [1,] -0.1439503  0.007217439  0.04066458
 [2,]  0.1154014 -0.009312094 -0.10422833
 [3,]  0.1673553  0.117909836  0.03056590

 , , rep2

             [,1]         [,2]        [,3]
 [1,] -0.14248417  0.004972831  0.03475940
 [2,]  0.09739824 -0.008022416 -0.09583761
 [3,]  0.17839128  0.122139269  0.03668812

...
在输入示例上使用Lappy:

>unaligned_coords
$individual1
, , rep1

         [,1]      [,2]     [,3]
[1,] 58.81923  2.452332 273.2005
[2,] 68.24838 -4.298481 271.2884
[3,] 69.58006 -1.127088 270.0316

, , rep2

         [,1]      [,2]     [,3]
[1,] 58.82360  2.485687 273.1929
[2,] 68.14501 -4.233420 271.3564
[3,] 69.02335 -0.875766 270.4671

$individual2
, , rep1

         [,1]       [,2]     [,3]
[1,] 58.64723 -1.7827113 271.4866
[2,] 69.53938 -7.0807052 274.4347
[3,] 72.35068  0.1114307 272.1112

, , rep2

         [,1]       [,2]     [,3]
[1,] 58.63091 -1.7735939 271.4576
[2,] 68.78160 -6.9430161 274.1252
[3,] 73.07706  0.3313497 272.1727

...
aligned_coords <- lapply(unaligned_coords, gpagen)
>aligned_coords
$individual1
 , , rep1

            [,1]         [,2]         [,3]
 [1,] -0.1838745 -0.002361134  0.001343360
 [2,]  0.1717784 -0.065992358 -0.003245113
 [3,]  0.1701612  0.025533125 -0.068783434

 , , rep2

            [,1]        [,2]          [,3]
 [1,] -0.1844239  0.00147890  0.0001282347
 [2,]  0.1846240 -0.07485290 -0.0031490047
 [3,]  0.1681969  0.02331805 -0.0627923402

$individual2
 , , rep1

            [,1]         [,2]        [,3]
 [1,] -0.1439503  0.007217439  0.04066458
 [2,]  0.1154014 -0.009312094 -0.10422833
 [3,]  0.1673553  0.117909836  0.03056590

 , , rep2

             [,1]         [,2]        [,3]
 [1,] -0.14248417  0.004972831  0.03475940
 [2,]  0.09739824 -0.008022416 -0.09583761
 [3,]  0.17839128  0.122139269  0.03668812

...
所需输出示例:

>unaligned_coords
$individual1
, , rep1

         [,1]      [,2]     [,3]
[1,] 58.81923  2.452332 273.2005
[2,] 68.24838 -4.298481 271.2884
[3,] 69.58006 -1.127088 270.0316

, , rep2

         [,1]      [,2]     [,3]
[1,] 58.82360  2.485687 273.1929
[2,] 68.14501 -4.233420 271.3564
[3,] 69.02335 -0.875766 270.4671

$individual2
, , rep1

         [,1]       [,2]     [,3]
[1,] 58.64723 -1.7827113 271.4866
[2,] 69.53938 -7.0807052 274.4347
[3,] 72.35068  0.1114307 272.1112

, , rep2

         [,1]       [,2]     [,3]
[1,] 58.63091 -1.7735939 271.4576
[2,] 68.78160 -6.9430161 274.1252
[3,] 73.07706  0.3313497 272.1727

...
aligned_coords <- lapply(unaligned_coords, gpagen)
>aligned_coords
$individual1
 , , rep1

            [,1]         [,2]         [,3]
 [1,] -0.1838745 -0.002361134  0.001343360
 [2,]  0.1717784 -0.065992358 -0.003245113
 [3,]  0.1701612  0.025533125 -0.068783434

 , , rep2

            [,1]        [,2]          [,3]
 [1,] -0.1844239  0.00147890  0.0001282347
 [2,]  0.1846240 -0.07485290 -0.0031490047
 [3,]  0.1681969  0.02331805 -0.0627923402

$individual2
 , , rep1

            [,1]         [,2]        [,3]
 [1,] -0.1439503  0.007217439  0.04066458
 [2,]  0.1154014 -0.009312094 -0.10422833
 [3,]  0.1673553  0.117909836  0.03056590

 , , rep2

             [,1]         [,2]        [,3]
 [1,] -0.14248417  0.004972831  0.03475940
 [2,]  0.09739824 -0.008022416 -0.09583761
 [3,]  0.17839128  0.122139269  0.03668812

...
Lappy可以这样做吗?我尝试了以下方法:

aligned_coords <- lapply(unaligned_coords, gpagen)$coords

在应用
gpagen
函数后,我们可以使用匿名函数调用来提取
coords

library(geomorph)
lapply(unaligned_coords, function(x) gpagen(x)$coords)
数据
set.seed(24)
未对齐的坐标