You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be useful to allow janitor::tabyl() to wrap labelled variables in as_factor() to convert variables to factors on the fly.
There is a workaround, in the reprex below, but it would be nice to have the second example work just because it's such easy syntax.
library(labelled)
v<- labelled(sample(c(1,2), size=100, replace=T), c(yes=1, no=2))
x<-labelled(sample(c(1,2), size=100, replace=T), c(male=1, female=2))
df<-data.frame(v, x)
library(tidyverse)
library(janitor)
as_factor(df)
# This worksdf %>%
as_factor() %>%
tabyl(., v, x)
# This does not but would be desirable
tabyl(df, as_factor(v), as_factor(x))
The text was updated successfully, but these errors were encountered:
I don't think that's possible, for the latter syntax. I'd like to do the same thing often with is.na() to check for missingness. But I first have to convert each variable with is.na() in a preceding call.
The only way I see would be to add an argument like factorize = T, but we try to avoid adding new arguments to functions and this is a very specialized case for users of the labelled package.
I will close this issue, but feel free to comment if there's something I'm missing.
It would be useful to allow
janitor::tabyl()
to wrap labelled variables inas_factor()
to convert variables to factors on the fly.There is a workaround, in the reprex below, but it would be nice to have the second example work just because it's such easy syntax.
The text was updated successfully, but these errors were encountered: