我不明白skim中关于列表变量的n_unique值的含义:
library(tidyverse)
library(skimr)
skim(starwars)
以下是结果的一部分,关于数据集中的三个列表变量:
现在,数据集中有 10 种不同的车辆,因此 n_unique 为 11 是有意义的(包括星球大战角色不使用任何车辆的空情况)。在整部电影中,角色可以使用最少零辆车辆 (min_length) 到最多两辆不同车辆 (max_length)。 还有 16 艘星舰,角色可以使用零到五艘不同的星舰,所以一切都有意义。
但是,电影只有七部。因此,n_unique 应该是 7 而不是 24。此外,一个角色确实可以在至少一部电影中出现 (min_length),最多可以在所有七部电影中出现 (max_length)。
单个电影有 7 个值,但如果比较列表元素之间的值,则有 24 个独特元素。
例如,如果第一个元素是 [
The Phantom Menace
, Revenge of the Sith
],第二个元素是 [The Phantom Menace
],那么这两个元素是不同的。
library(tidyverse)
library(skimr)
# Count unique individual films
starwars$films |>
unlist() |>
unique() |>
length()
#> [1] 7
# Count unique list elements
starwars$films |>
unique() |>
length()
#> [1] 24