Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 向量子集与列表子集_R - Fatal编程技术网

R 向量子集与列表子集

R 向量子集与列表子集,r,R,鉴于: 鉴于shining_list[[c(3,3)]]返回: actors_vector <- c("Jack Nicholson", "Shelley Duvall", "Danny Lloyd", "Scatman Crothers", "Barry Nelson") reviews_factor <- factor(c("Good", "OK", "Good", "Perfect",

鉴于:

鉴于
shining_list[[c(3,3)]]
返回:

actors_vector <- c("Jack Nicholson", "Shelley Duvall", "Danny Lloyd", 
                   "Scatman Crothers", "Barry Nelson")

reviews_factor <- factor(c("Good", "OK", "Good", "Perfect", 
                           "Bad", "Perfect", "Good"), 
                         levels = c("Bad", "OK", "Good", "Perfect"),
                         ordered = TRUE)

shining_list <- list(title = "The Shining", 
                     actors = actors_vector,
                     reviews = reviews_factor)

shining_list
$title
[1] "The Shining"

$actors
[1] "Jack Nicholson"   "Shelley Duvall"   "Danny Lloyd"      "Scatman Crothers"
[5] "Barry Nelson"    

$reviews
[1] Good    OK      Good    Perfect Bad     Perfect Good   
Levels: Bad < OK < Good < Perfect

$boxoffice
               US Non-US
First release  39     47
Director's cut 18     14
[1] Good
Levels: Bad < OK < Good < Perfect

这是关于向量子集与列表子集的一节。

这很可能是因为因子不是向量:

[1] 3
在某些情况下,此结构将崩溃,只剩下整数表示形式。我认为你的例子就是其中之一,其他几个例子是:

unclass(reviews)
## [1] 3 2 3 4 1 4 3
## attr(,"levels")
## [1] "Bad"     "OK"      "Good"    "Perfect"

你在评论中有一个因素。当您使用
c(3,3)
进行提取时,它被转换为一个整数。它与[[可以递归地应用于列表相冲突,因此,如果单个索引
i
是长度
p
的向量,
alist[[i]]
相当于
alist[[i1]]
..
[[ip]
在列表中提供除最终索引结果以外的所有结果。”,但是
list[[3]]
返回
[1]Good
/
级别:Bad
而不仅仅是
[1]3
unclass(reviews)
## [1] 3 2 3 4 1 4 3
## attr(,"levels")
## [1] "Bad"     "OK"      "Good"    "Perfect"
c(reviews[3], reviews[4])
## [1] 3 4
ifelse(TRUE, reviews[1], reviews[2])
## [1] 3