当从数组降维为矩阵时,base::drop()是否应保留维度名称?
关于base::drop()移除维度名称的疑问
我发现当数组的维度没有设置元素特定名称时,base::drop()会直接移除整个数组的维度名称。以下是复现代码:
a = array( data = 1:12, dim = c(2,3,4), dimnames = list("test" = NULL, "test2" = NULL, "test3" = NULL)) a[1,,,drop = FALSE] |> dimnames() #> $test #> NULL #> #> $test2 #> NULL #> #> $test3 #> NULL a[1,,,drop = TRUE] |> dimnames() # 我认为这等同于`a[1,,,drop = FALSE] |> drop()` #> NULL
我原本期望执行a[1,,,drop = FALSE] |> drop()后,返回结果的维度名称应该是这样的:
#> $test2 #> NULL #> #> $test3 #> NULL
请问这是drop()函数的预期行为吗?
内容的提问来源于stack exchange,提问作者Doug Ezra Morrison
相关产品推荐
相关产品推荐

