within-operators: Operators to abbreviate use of "with" and "within"

within-operatorsR Documentation

Operators to abbreviate use of "with" and "within"

Description

The operators %$% and %$$% provide abbrevitions for calls to with() and within() respectively. The function Within() is a variant of with() were the resulting data frame contains any newly created variables in the order in which they are created (and not in the reverse order).

Usage

data %$% expr
data %$$% expr
Within(data,expr,...)
## S3 method for class 'data.frame'
Within(data,expr,...)

Arguments

data

a data frame or similar object, see with and within

expr

a single or compound expression (i.e. several expressions enclosed in curly braces), see with and within

...

Further arguments, currently ignored

See Also

with and within in package "base".

Examples

df <- data.frame(a = 1:7,
                 b = 7:1)

df

df <- within(df,{
  ab <- a + b
  a2b2 <- a^2 + b^2
})
df

df <- data.frame(a = 1:7,
                 b = 7:1)
df <- Within(df,{
  ab <- a + b
  a2b2 <- a^2 + b^2
})
df


df <- data.frame(a = 1:7,
                 b = 7:1)
df

ds <- as.data.set(df)
ds

df %$$% {
  ab <- a + b
  a2b2 <- a^2 + b^2
}
df

ds %$$% {
  ab <- a + b
  a2b2 <- a^2 + b^2
}
ds

df %$% c(a.ssq = sum(a^2),
         b.ssq = sum(b^2))

memisc documentation built on Oct. 24, 2024, 5:07 p.m.