View source: R/star_rhs_names.R
| star_rhs_names | R Documentation |
stargazer outputTo replace the names of the RHS variables in stargazer.
The function also allows for an optional second line.
star_rhs_names(star, pattern, line1, line2 = NULL)
star |
the |
pattern |
the regular expression pattern |
line1 |
the variable name in the first line |
line2 |
the optional variable name in the second line. The
|
Note: the pattern and line1 arguments must have the
same length. If line2 is not NULL, it must have the
same length as pattern and line1. Also, line2
will be inserted into star directly.
a character vector with the updated stargazer output
## -- Regression example -- ##
library(stargazer)
data(mtcars)
mod.mtcars.1 <- lm(mpg ~ hp + wt, mtcars)
mod.mtcars.2 <- lm(mpg ~ hp + wt + cyl, mtcars)
##Latex example
star.out <- stargazer(mod.mtcars.1, mod.mtcars.2, type = "latex")
print(star.out)
##Update the names hp and wt using one line only
star.out.1 <- star_rhs_names(star.out,
pattern = c("hp", "wt"),
line1 = c("horsepower", "weight")
)
print(star.out.1)
##Sometimes variables can have really long names and
##would be best written on 2 lines
star.out.1 <- star_rhs_names(star.out,
pattern = c("hp", "wt"),
line1 = c("horse-", "weight"),
line2 = c("power", "")
)
print(star.out.1)
##Text example
##Note that star_rhs_names() will NOT adjust the
##length of the character elements if the variable names in line1
##or line 2 are longer than those that they are replacing
star.out <- stargazer(mod.mtcars.1, mod.mtcars.2, type = "text")
print(star.out)
##Update the names hp and wt using oneline
star.out.1 <- star_rhs_names(star.out,
pattern = c("hp", "wt"),
line1 = c("horsepower", "weight")
)
print(star.out.1)
##Sometimes variables can have really long names and
##would be best written on 2 lines
star.out.1 <- star_rhs_names(star.out,
pattern = c("hp", "wt"),
line1 = c("horse-", "weight"),
line2 = c("power", "")
)
print(star.out.1)
## -- Summary stats example -- ##
##latex example
star.out.summ <- stargazer(mtcars[,c("mpg", "hp", "wt")], type = "latex")
print(star.out.summ)
star.out.summ <- star_rhs_names(star.out.summ,
pattern = c("hp", "wt"),
line1 = c("horsepower", "weight")
)
print(star.out.summ)
##text example
star.out.summ <- stargazer(mtcars[,c("mpg", "hp", "wt")], type = "text")
star.out.summ <- star_rhs_names(star.out.summ,
pattern = c("hp", "wt"),
line1 = c("horsepower", "weight")
)
print(star.out.summ)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.