當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。