View source: R/star_rhs_order.R
star_rhs_order | R Documentation |
Use regular expressions to manipulate the right hand side
variables in in a stargazer regrssion or table.
This function is compatible works with stargazer
output of type latex
and text
.
star_rhs_order(star, pattern, reg = TRUE)
star |
the stargazer table |
pattern |
a vector of regular expressions which the order with which the right-hand-side variables will be used |
reg |
(logical) set to TRUE for a regression; defaults to
|
character vector with stargazer output with the updated order
## -- 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)
star.out <- star_rhs_order(star.out, c("cyl", "hp", "wt", "Constant"))
print(star.out)
##text example
star.out <- stargazer(mod.mtcars.1, mod.mtcars.2, type = "text")
print(star.out)
star.out <- star_rhs_order(star.out, c("cyl", "hp", "wt", "Constant"))
print(star.out)
## -- 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_order(star.out.summ, c("hp", "mpg", "wt"), reg = FALSE)
print(star.out.summ)
##text example
star.out.summ <- stargazer(mtcars[,c("mpg", "hp", "wt")], type = "text")
print(star.out.summ)
star.out.summ <- star_rhs_order(star.out.summ, c("hp", "mpg", "wt"), reg = FALSE)
print(star.out.summ)
## -- Keeping a subset of all variables -- ##
##As star_rhs_order() matches based on regular expressions,
##it can also be used to show only a subset of all variables
##Latex example
star.out <- stargazer(mod.mtcars.1, mod.mtcars.2, type = "latex")
print(star.out)
##Only keep hp
star.out <- star_rhs_order(star.out, c("hp"))
print(star.out)
##text example
star.out <- stargazer(mod.mtcars.1, mod.mtcars.2, type = "text")
print(star.out)
##Only keep hp
star.out <- star_rhs_order(star.out, c("hp"))
print(star.out)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.