当R中缺少标签时,如何获取此数据结构中的项目数?
我想得到有效项的计数,即60,当您执行当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(
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
你还需要帮助吗?