View source: R/star_lhs_names.R
| star_lhs_names | R Documentation |
stargazer outputTo replace the names of the RFHS variables in stargazer.
The function also allows for optional second and third lines
star_lhs_names(
star,
pattern,
line1,
line2 = NULL,
line3 = NULL,
multicol = 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 |
line3 |
the optional variable name in teh third line |
multicol |
if not |
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
character vector with stargazer output with the updated LHS variable names
## -- 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)
##For Multicolumn centered columns. Using multicolumn
##for the column labels can be useful for siunitx
##columns or if the column labels have a different alignment
##than the rest of the table
star.out.4 <- star_lhs_names(star.out,
pattern = c("mpg", "hp"),
line1 = c("miles", "horse-"),
line2 = c("per", "power"),
line3 = c("gallon", ""),
multicol = c("c")
)
print(star.out.4)
##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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.