mutar {dat}R Documentation

Tools for Data Frames

Description

mutar is literally the same function as [.DataFrame and can be used as interface to dplyr or data.table. Other functions here listed are a convenience to mimic dplyr's syntax in a R CMD check friendly way. These functions can also be used with S4 data.frame(s) / data_frame(s) / data.table(s). They will always try to preserve the input class.

Usage

mutar(x, i, j, ..., by, sby, drop)

filtar(x, i)

sumar(x, ..., by)

withReference(expr)

Arguments

x

(DataFrame | data.frame)

i

(logical | numeric | integer | OneSidedFormula | TwoSidedFormula | FormulaList) see the examples.

j

(logical | character | TwoSidedFormula | FormulaList | function) character beginning with '^' are interpreted as regular expression

...

arbitrary number of args
in [ (TwoSidedFormulas)
in constructor see tibble

by

(character) variables to group by. by will be used to do transformations within groups. sby will collapse each group to one row.

sby

(character) variables to group by. by will be used to do transformations within groups. sby will collapse each group to one row.

drop

(ignored) never drops the class.

expr

(expression) any R expression that should be evaluated using data tables reference semantics on data transformations.

Details

The real workhorse of this interface is mutar. All other functions exist to ease the transition from dplyr.

OneSidedFormula is always used for subsetting rows.

TwoSidedFormula is used instead of name-value expressions. Instead of writing x = 1 you simply write x ~ 1.

FormulaList can be used to repeat the same operation on different columns. See more details in FL.

See Also

extract, DataFrame, FL

Examples

data("airquality")
airquality %>%
  filtar(~Month > 4) %>%
  mutar(meanWind ~ mean(Wind), by = "Month") %>%
  sumar(meanWind ~ mean(Wind), by = "Month") %>%
  extract("meanWind")

airquality %>%
  sumar(
    .n ~ mean(.n) | c("Wind", "Temp"),
    by = "Month"
  )

# Enable data.tables reference semantics with:
withReference({
  x <- data.table::data.table(x = 1)
  mutar(x, y ~ 2)
})

## Not run: 
# Use dplyr as back-end:
options(dat.use.dplyr = TRUE)
x <- data.frame(x = 1)
mutar(x, y ~ dplyr::n())

## End(Not run)


[Package dat version 0.5.0 Index]