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


R dtplyr head.dtplyr_step 對第一行或最後一行進行子集化

這些是基本泛型 head()tail() 的方法。它們沒有被翻譯。

用法

# S3 method for dtplyr_step
head(x, n = 6L, ...)

# S3 method for dtplyr_step
tail(x, n = 6L, ...)

參數

x

lazy_dt()

n

要選擇的行數。可以使用負數來代替從另一端刪除行。

...

傳遞給head() /tail()

例子

library(dplyr, warn.conflicts = FALSE)
dt <- lazy_dt(data.frame(x = 1:10))

# first three rows
head(dt, 3)
#> Source: local data table [3 x 1]
#> Call:   head(`_DT17`, n = 3)
#> 
#>       x
#>   <int>
#> 1     1
#> 2     2
#> 3     3
#> 
#> # Use as.data.table()/as.data.frame()/as_tibble() to access results
# last three rows
tail(dt, 3)
#> Source: local data table [3 x 1]
#> Call:   tail(`_DT17`, n = 3)
#> 
#>       x
#>   <int>
#> 1     8
#> 2     9
#> 3    10
#> 
#> # Use as.data.table()/as.data.frame()/as_tibble() to access results

# drop first three rows
tail(dt, -3)
#> Source: local data table [7 x 1]
#> Call:   tail(`_DT17`, n = -3)
#> 
#>       x
#>   <int>
#> 1     4
#> 2     5
#> 3     6
#> 4     7
#> 5     8
#> 6     9
#> # … with 1 more row
#> 
#> # Use as.data.table()/as.data.frame()/as_tibble() to access results
源代碼:R/step-call.R

相關用法


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