Reputation: 1792
I am trying to pipe into expss::uselabels()
.
A simple replicable example of what I'm trying to do (without the pipe), would be a labelled lm()
model:
library(tidyverse) library(expss) df <- mtcars df <- apply_labels(df, cyl = "Number of Cylinders", disp = "Displacement") fit_1 <- df %>% use_labels(lm(formula = mpg ~ disp + cyl)) summary(fit_1)
which gives labelled coefficients in the lm
output:
# > Coefficients: #> Estimate Std. Error t value Pr(>|t|) #> (Intercept) 34.66099 2.54700 13.609 4.02e-14 *** #> Displacement -0.02058 0.01026 -2.007 0.0542 . #> `Number of Cylinders` -1.58728 0.71184 -2.230 0.0337 *
My questions: can I first take an lm()
model and then pipe into use_labels()
? I've tried below, but I must be refering to the two paramaters incorrectly.
fit_1<- df %>% lm(formula = mpg ~ disp + cyl) %>% use_labels(data = .x, expr = .y)
Upvotes: 2
Views: 207
Reputation: 4846
use_labels
works in a very simple and straightforward way. It just replaces in the expression all variables names with their labels. Variables are searched in the first argument (data.frame). As @alistaire already said all this actions are performed before the evaluation of the supplied expression, e. g. before calculating result of the lm(formula = mpg ~ disp + cyl)
. So answer is on your question is 'No'. You cannot apply use_labels
on the already calculated result.
Upvotes: 1