Learn R Programming

memisc (version 0.99.31.8)

within-operators: 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 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

Run this code
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))

Run the code above in your browser using DataLab