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


R dtplyr select.dtplyr_step 使用名稱對列進行子集化

這是 dplyr select() 泛型的方法。它被轉換為 [.data.tablej 參數。

用法

# S3 method for dtplyr_step
select(.data, ...)

參數

.data

一個lazy_dt()

...

< tidy-select > 一個或多個未加引號的表達式,以逗號分隔。變量名稱可以像 DataFrame 中的位置一樣使用,因此可以使用 x:y 等表達式來選擇一係列變量。

例子

library(dplyr, warn.conflicts = FALSE)

dt <- lazy_dt(data.frame(x1 = 1, x2 = 2, y1 = 3, y2 = 4))

dt %>% select(starts_with("x"))
#> Source: local data table [1 x 2]
#> Call:   `_DT36`[, .(x1, x2)]
#> 
#>      x1    x2
#>   <dbl> <dbl>
#> 1     1     2
#> 
#> # Use as.data.table()/as.data.frame()/as_tibble() to access results
dt %>% select(ends_with("2"))
#> Source: local data table [1 x 2]
#> Call:   `_DT36`[, .(x2, y2)]
#> 
#>      x2    y2
#>   <dbl> <dbl>
#> 1     2     4
#> 
#> # Use as.data.table()/as.data.frame()/as_tibble() to access results
dt %>% select(z1 = x1, z2 = x2)
#> Source: local data table [1 x 2]
#> Call:   `_DT36`[, .(z1 = x1, z2 = x2)]
#> 
#>      z1    z2
#>   <dbl> <dbl>
#> 1     1     2
#> 
#> # Use as.data.table()/as.data.frame()/as_tibble() to access results

相關用法


注:本文由純淨天空篩選整理自Hadley Wickham等大神的英文原創作品 Subset columns using their names。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。