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


R dtplyr transmute.dtplyr_step 創建新列,刪除舊列

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

用法

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

參數

.data

一個lazy_dt()

...

< data-masking > Name-value 對。名稱給出輸出中列的名稱。

該值可以是:

  • 長度為1的向量,將被回收到正確的長度。

  • 與當前組(或整個數據幀,如果未分組)長度相同的向量。

  • NULL ,刪除該列。

  • DataFrame 或小標題,用於在輸出中創建多個列。

例子

library(dplyr, warn.conflicts = FALSE)

dt <- lazy_dt(dplyr::starwars)
dt %>% transmute(name, sh = paste0(species, "/", homeworld))
#> Source: local data table [87 x 2]
#> Call:   `_DT40`[, .(name = name, sh = paste0(species, "/", homeworld))]
#> 
#>   name           sh            
#>   <chr>          <chr>         
#> 1 Luke Skywalker Human/Tatooine
#> 2 C-3PO          Droid/Tatooine
#> 3 R2-D2          Droid/Naboo   
#> 4 Darth Vader    Human/Tatooine
#> 5 Leia Organa    Human/Alderaan
#> 6 Owen Lars      Human/Tatooine
#> # … with 81 more rows
#> 
#> # Use as.data.table()/as.data.frame()/as_tibble() to access results

相關用法


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