length
?
> length(mylist)
[1] 2
题
我知道在R中,您可以通过双括号索引,即 mylist[[1]]
. 。您如何计算该列表中元素的数量(不是每个列表中的元素数量,而是最大值 n
在 mylist[[n]]
)?我试过了 NROW
, NCOL
, dim
, ,其他。
某些功能所需行为的一些示例代码 num.items(list)
:
require(testthat)
mylist <- list(array(rnorm(4),dim=c(2,2)),array(rnorm(4),dim=c(2,2)))
expect_that( num.items(mylist), equals(2) )
解决方案
length
?
> length(mylist)
[1] 2