star_lhs_names: To replace the names of the LHS variables in 'stargazer'...

Description Usage Arguments Details Value Examples

View source: R/star_lhs_names.R

Description

To replace the names of the RFHS variables in stargazer. The function also allows for optional second and third lines

Usage

1
star_lhs_names(star, pattern, line1, line2 = NULL, line3 = NULL)

Arguments

star

the stargazer output

pattern

the regular expression pattern

line1

the variable name in the first line

line2

the optional variable name in the second line

line3

the optional variable name in teh third line

Details

Note: the pattern and line1 arguments must have the same length. If line2 and line3 are not NULL, they must have the same length as pattern and line1

Value

character vector with stargazer output with the updated LHS variable names

Examples

 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
## -- Regression Example -- ##
library(stargazer)
data(mtcars)
mod.mtcars.1 <- lm(mpg ~ hp + wt, mtcars)
mod.mtcars.2 <- lm(mpg ~ hp + wt + cyl, mtcars)
mod.mtcars.3 <- lm(hp ~ wt + cyl, mtcars)
##latex example
star.out <- stargazer(mod.mtcars.1, mod.mtcars.2, mod.mtcars.3,
                      type = "latex")
print(star.out)
##update the LHS variable names using one line only
star.out.1 <- star_lhs_names(star.out,
                             pattern = c("mpg", "hp"),
                             line1 = c("miles per gallon", "horsepower")
                            )
print(star.out.1)
##Sometimes variables can have really long names and
##would be best written on 2 lines
star.out.2 <- star_lhs_names(star.out,
                             pattern = c("mpg", "hp"),
                             line1 = c("miles per", "horse-"),
                             line2 = c("gallon", "power")
                            )
print(star.out.2)
##For this example, three lines might be even better
star.out.3 <- star_lhs_names(star.out,
                             pattern = c("mpg", "hp"),
                             line1 = c("miles", "horse-"),
                             line2 = c("per", "power"),
                             line3 = c("gallon", "")
                            )
print(star.out.3)

##Text Examples
##Note that star_lhs_names() will NOT adjust the
##length of the character elements if the variable names in line1,
##line 2, or line3 are longer than those that they are replacing
star.out <- stargazer(mod.mtcars.1, mod.mtcars.2, mod.mtcars.3,
                      type = "text")
print(star.out)
##update the LHS variable names using one line only
star.out.1 <- star_lhs_names(star.out,
                             pattern = c("mpg", "hp"),
                             line1 = c("miles per gallon", "horsepower")
                            )
print(star.out.1)
##Sometimes variables can have really long names and
##would be best written on 2 lines
star.out.2 <- star_lhs_names(star.out,
                             pattern = c("mpg", "hp"),
                             line1 = c("miles per", "horse-"),
                             line2 = c("gallon", "power")
                            )
print(star.out.2)
##For this example, three lines might be even better
star.out.3 <- star_lhs_names(star.out,
                             pattern = c("mpg", "hp"),
                             line1 = c("miles", "horse-"),
                             line2 = c("per", "power"),
                             line3 = c("gallon", "")
                            )
print(star.out.3)

ChandlerLutz/starpolish documentation built on June 1, 2017, 11:09 p.m.