dplyr (version 0.1.1)

manip_grouped_dt: Data manipulation for grouped data tables.

Description

Data manipulation for grouped data tables.

Usage

# S3 method for grouped_dt
filter(.data, ...)

# S3 method for grouped_dt summarise(.data, ...)

# S3 method for grouped_dt mutate(.data, ..., inplace = FALSE)

# S3 method for grouped_dt arrange(.data, ...)

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

Arguments

.data
a data table
...
variables interpreted in the context of .data
inplace
if FALSE (the default) the data frame will be copied prior to modification to avoid changes propagating via reference.

Examples

Run this code
if (require("data.table") && require("hflights")) {
hflights2 <- tbl_dt(hflights)
by_dest <- group_by(hflights2, Dest)
filter(by_dest, ArrDelay == max(ArrDelay, na.rm = TRUE))
summarise(by_dest, arr = mean(ArrDelay, na.rm = TRUE))

# Normalise arrival and departure delays by airport
scaled <- mutate(by_dest, arr_z = scale(ArrDelay), dep_z = scale(DepDelay))
select(scaled, Year:DayOfWeek, Dest, arr_z:dep_z)

arrange(by_dest, desc(ArrDelay))
select(by_dest, -(DayOfWeek:TailNum))

# All manip functions preserve grouping structure, except for summarise
# which removes a grouping level
by_day <- group_by(hflights, Year, Month, DayofMonth)
by_month <- summarise(by_day, delayed = sum(ArrDelay > 0, na.rm = TRUE))
by_month
summarise(by_month, delayed = sum(delayed))

# You can also manually ungroup:
ungroup(by_day)
}

Run the code above in your browser using DataCamp Workspace