删除R中多维数组中的一层命名

问题描述 投票:-2回答:1

比较以下数组:

> str(arr)
 num [1:77, 1:65, 1:40] NA NA NA NA NA NA NA NA NA NA ...
 - attr(*, "dimnames")=List of 3
  ..$ : chr [1:77] "2020-04-15T00:29:00.000000000+00:00" "2020-04-15T00:33:00.000000000+00:00" "2020-04-15T00:43:00.000000000+00:00" "2020-04-15T00:48:00.000000000+00:00" ...
  ..$ : chr [1:65] "1" "2" "3" "4" ...
  ..$ : chr [1:40] "v_1" "v_2" "v_3" "v_4" ...
> str(arr1)
 num [1:77, 1:65, 1:40] NA NA NA NA NA NA NA NA NA NA ...
 - attr(*, "dimnames")=List of 3
  ..$ mynano  : chr [1:77] "2020-04-15T00:29:00.000000000+00:00" "2020-04-15T00:33:00.000000000+00:00" "2020-04-15T00:43:00.000000000+00:00" "2020-04-15T00:48:00.000000000+00:00" ...
  ..$ mycat   : chr [1:65] "1" "2" "3" "4" ...
  ..$ values  : chr [1:40] "v_1" "v_2" "v_3" "v_4" ...

您可以看到arr1具有另外一层名称,即:mynanomycatvalues,而arr没有。

如何在arr1中删除这些名称,同时保持其暗号,如arr一样?

r arrays multidimensional-array
1个回答
0
投票

在第二个示例中,数组的dimnames是一个命名列表,因此您必须删除此列表的名称:

names(dimnames(arr1)) <- NULL
© www.soinside.com 2019 - 2024. All rights reserved.