Debian Codegraph @

man/within-operators.Rd

raw
1 \name{within-operators}
2 \alias{Within}
3 \alias{Within.data.frame}
4 \alias{\%$\%}
5 \alias{\%$$\%}
6 \title{Operators to abbreviate use of "with" and "within"}
7 \description{The operators \code{\%$\%} and \code{\%$$\%} provide
8 abbrevitions for calls to \code{with()} and \code{within()}
9 respectively.
10 The function \code{Within()} is a variant of \code{with()} were
11 the resulting data frame contains any newly created variables in the
12 order in which they are created (and not in the reverse order).
13 }
14 \usage{
15 data \%$\% expr
16 data \%$$\% expr
17 Within(data,expr,\dots)
18 \method{Within}{data.frame}(data,expr,\dots)
19 }
20 \arguments{
21 \item{data}{a data frame or similar object, see \code{\link{with}} and \code{\link{within}}}
22 \item{expr}{a single or compound expression (i.e. several expressions
23 enclosed in curly braces), see \code{\link{with}} and
24 \code{\link{within}}}
25 \item{\dots}{Further arguments, currently ignored}
26 }
27 \seealso{\code{\link{with}} and \code{\link{within}} in package "base".}
28 \examples{
29 df <- data.frame(a = 1:7,
30 b = 7:1)
31
32 df
33
34 df <- within(df,{
35 ab <- a + b
36 a2b2 <- a^2 + b^2
37 })
38 df
39
40 df <- data.frame(a = 1:7,
41 b = 7:1)
42 df <- Within(df,{
43 ab <- a + b
44 a2b2 <- a^2 + b^2
45 })
46 df
47
48
49 df <- data.frame(a = 1:7,
50 b = 7:1)
51 df
52
53 ds <- as.data.set(df)
54 ds
55
56 df \%$$\% {
57 ab <- a + b
58 a2b2 <- a^2 + b^2
59 }
60 df
61
62 ds \%$$\% {
63 ab <- a + b
64 a2b2 <- a^2 + b^2
65 }
66 ds
67
68 df \%$\% c(a.ssq = sum(a^2),
69 b.ssq = sum(b^2))
70 }