当R中缺少标签时,如何获取此数据结构中的项目数?

当R中缺少标签时,如何获取此数据结构中的项目数?,r,list,matrix,R,List,Matrix,我想得到有效项的计数,即60,当您执行str(res.r)时,您可以看到以下字段,其中字段没有名称,我无法引用。 通常,我的数据是像data.frame(V1,V2)一样生成的,您可以执行res.r$V1,但在这里您不能。 我也尝试了res.r$1,但没有成功 # ..$ : chr [1:60] "cyl" "disp" "hp" "wt" ... # ..$ : chr [1:2] "row" "col" 最小示例 通过lista[[1]]引用最简单的示例 lista <- c(

我想得到有效项的计数,即60,当您执行
str(res.r)
时,您可以看到以下字段,其中字段没有名称,我无法引用。 通常,我的数据是像
data.frame(V1,V2)
一样生成的,您可以执行
res.r$V1
,但在这里您不能。 我也尝试了
res.r$1
,但没有成功

#  ..$ : chr [1:60] "cyl" "disp" "hp" "wt" ...
#  ..$ : chr [1:2] "row" "col"
最小示例 通过
lista[[1]]
引用最简单的示例

lista <- c( list(seq(1,5)), list(seq(1,7)) )

str(lista)

str(lista[[1]])
#List of 2
# $ : int [1:5] 1 2 3 4 5
# $ : int [1:7] 1 2 3 4 5 6 7
# int [1:5] 1 2 3 4 5
输出

#Attaching package: ‘gplots’

#The following object is masked from ‘package:stats’:

#    lowess

# int [1:60, 1:2] 2 3 4 6 11 1 5 7 8 9 ...
# - attr(*, "dimnames")=List of 2
#  ..$ : chr [1:60] "cyl" "disp" "hp" "wt" ...
#  ..$ : chr [1:2] "row" "col"
Attaching package: ‘gplots’

The following object is masked from ‘package:stats’:

    lowess

 int [1:60, 1:2] 2 3 4 6 11 1 5 7 8 9 ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:60] "cyl" "disp" "hp" "wt" ...
  ..$ : chr [1:2] "row" "col"
 int 2
 int 3
 int 60
 int 2
预期输出:重要项目的数量,此处为60

R:3.3.1

操作系统:Debian 8.5

数据结构是矩阵,而不是列表列表,尽管看起来是这样的。 做

输出

#Attaching package: ‘gplots’

#The following object is masked from ‘package:stats’:

#    lowess

# int [1:60, 1:2] 2 3 4 6 11 1 5 7 8 9 ...
# - attr(*, "dimnames")=List of 2
#  ..$ : chr [1:60] "cyl" "disp" "hp" "wt" ...
#  ..$ : chr [1:2] "row" "col"
Attaching package: ‘gplots’

The following object is masked from ‘package:stats’:

    lowess

 int [1:60, 1:2] 2 3 4 6 11 1 5 7 8 9 ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:60] "cyl" "disp" "hp" "wt" ...
  ..$ : chr [1:2] "row" "col"
 int 2
 int 3
 int 60
 int 2

你还需要帮助吗?