当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


R dtplyr distinct.dtplyr_step 子集不同/唯一行


这是 dplyr distinct() 泛型的方法。它被翻译为 data.table::unique.data.table()

用法

# S3 method for dtplyr_step
distinct(.data, ..., .keep_all = FALSE)

参数

.data

lazy_dt()

...

< data-masking > 确定唯一性时使用的可选变量。如果给定的输入组合有多行,则仅保留第一行。如果省略,将使用 DataFrame 中的所有变量。

.keep_all

如果是 TRUE ,则将所有变量保留在 .data 中。如果 ... 的组合不不同,则保留第一行值。

例子

library(dplyr, warn.conflicts = FALSE)
df <- lazy_dt(data.frame(
  x = sample(10, 100, replace = TRUE),
  y = sample(10, 100, replace = TRUE)
))

df %>% distinct(x)
#> Source: local data table [10 x 1]
#> Call:   unique(`_DT7`[, .(x)])
#> 
#>       x
#>   <int>
#> 1    10
#> 2     4
#> 3     1
#> 4     5
#> 5     7
#> 6     2
#> # … with 4 more rows
#> 
#> # Use as.data.table()/as.data.frame()/as_tibble() to access results
df %>% distinct(x, y)
#> Source: local data table [64 x 2]
#> Call:   unique(`_DT7`)
#> 
#>       x     y
#>   <int> <int>
#> 1    10     8
#> 2     4     3
#> 3     1     8
#> 4     1     6
#> 5     5     7
#> 6     7    10
#> # … with 58 more rows
#> 
#> # Use as.data.table()/as.data.frame()/as_tibble() to access results
df %>% distinct(x, .keep_all = TRUE)
#> Source: local data table [10 x 2]
#> Call:   unique(`_DT7`, by = "x")
#> 
#>       x     y
#>   <int> <int>
#> 1    10     8
#> 2     4     3
#> 3     1     8
#> 4     5     7
#> 5     7    10
#> 6     2     7
#> # … with 4 more rows
#> 
#> # Use as.data.table()/as.data.frame()/as_tibble() to access results
源代码:R/step-call.R

相关用法


注:本文由纯净天空筛选整理自Hadley Wickham等大神的英文原创作品 Subset distinct/unique rows。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。