浏览列表变量时,n_unique 值意味着什么?

问题描述 投票:0回答:1

我不明白skim中关于列表变量的n_unique值的含义:

library(tidyverse)
library(skimr)

skim(starwars)

以下是结果的一部分,关于数据集中的三个列表变量:

detail of the result of skim(starwars)

现在,数据集中有 10 种不同的车辆,因此 n_unique 为 11 是有意义的(包括星球大战角色不使用任何车辆的空情况)。在整部电影中,角色可以使用最少零辆车辆 (min_length) 到最多两辆不同车辆 (max_length)。 还有 16 艘星舰,角色可以使用零到五艘不同的星舰,所以一切都有意义。

但是,电影只有七部。因此,n_unique 应该是 7 而不是 24。此外,一个角色确实可以在至少一部电影中出现 (min_length),最多可以在所有七部电影中出现 (max_length)。

r tidyverse skimr
1个回答
0
投票

单个电影有 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
© www.soinside.com 2019 - 2024. All rights reserved.