File: formulize.Rd

package info (click to toggle)
r-cran-arsenal 3.6.3-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,788 kB
  • sloc: sh: 18; makefile: 5
file content (81 lines) | stat: -rw-r--r-- 2,305 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/formulize.R
\name{formulize}
\alias{formulize}
\title{formulize}
\usage{
formulize(
  y = "",
  x = "",
  ...,
  data = NULL,
  collapse = "+",
  collapse.y = collapse,
  escape = FALSE
)
}
\arguments{
\item{y, x, ...}{Character vectors, names, or calls to be collapsed (by \code{"+"}) and put left-to-right in the formula.
If \code{data} is supplied, these can also be numeric, denoting which column name to use. See examples.}

\item{data}{An R object with non-null column names.}

\item{collapse}{How should terms be collapsed? Default is addition.}

\item{collapse.y}{How should the y-terms be collapsed? Default is addition. Also accepts the special string "list",
which combines them into a multiple-left-hand-side formula, for use in other functions.}

\item{escape}{A logical indicating whether character vectors should be coerced to names (that is, whether names with spaces should
be surrounded with backticks or not)}
}
\description{
A shortcut to generate one-, two-, or many-sided formulas from vectors of variable names.
}
\examples{
## two-sided formula
f1 <- formulize("y", c("x1", "x2", "x3"))

## one-sided formula
f2 <- formulize(x = c("x1", "x2", "x3"))

## multi-sided formula
f3 <- formulize("y", c("x1", "x2", "x3"), c("z1", "z2"), "w1")

## can use numerics for column names
data(mockstudy)
f4 <- formulize(y = 1, x = 2:4, data = mockstudy)

## mix and match
f5 <- formulize(1, c("x1", "x2", "x3"), data = mockstudy)

## get an interaction
f6 <- formulize("y", c("x1*x2", "x3"))

## get only interactions
f7 <- formulize("y", c("x1", "x2", "x3"), collapse = "*")

## no intercept
f8 <- formulize("y", "x1 - 1")
f9 <- formulize("y", c("x1", "x2", "-1"))

## LHS as a list to use in arsenal functions
f10 <- formulize(c("y1", "y2", "y3"), c("x", "z"), collapse.y = "list")

## use in an lm
f11 <- formulize(2, 3:4, data = mockstudy)
summary(lm(f11, data = mockstudy))

## using non-syntactic names or calls (like reformulate example)
f12 <- formulize(as.name("+-"), c("`P/E`", "`\% Growth`"))
f12 <- formulize("+-", c("P/E", "\% Growth"), escape = TRUE)

f <- Surv(ft, case) ~ a + b
f13 <- formulize(f[[2]], f[[3]])

}
\seealso{
\code{\link[stats:delete.response]{reformulate}}
}
\author{
Ethan Heinzen
}