-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
viewdf messes up display of frequencies if variable value starts at 0 #945
Comments
Do you have a reproducible example? This works for me: set.seed(123)
d <- data.frame(
x = factor(sample(0:3, 20, TRUE)),
y = rnorm(20),
z = factor(sample(letters[1:4], 20, TRUE))
)
sjPlot::view_df(d, show.frq = TRUE, show.prc = TRUE)
Created on 2024-11-25 with reprex v2.1.1 Can you also try |
I have a data file in XLSX format where this happens, but not an example with random data. The code you asked me to run only throws an error message: "Error in |
What if you convert the tibble (from readxl, I guess) into a data frame and then try the code again? |
If I convert the tibble into a data frame, then the issue remains. |
When I convert the variable from numeric to categorial with "as.factor", the issue vanishes. If I then convert it back to numeric and re-apply the labels, the issue comes back. |
1 similar comment
When I convert the variable from numeric to categorial with "as.factor", the issue vanishes. If I then convert it back to numeric and re-apply the labels, the issue comes back. |
Try |
If you leave out the labeling, you can still see that there is an issue because the range of x is reported by sjPlot to be from 1 to 4 while it is actually from 0 to 3. I think that's where the issue is coming from. |
If a variable starts at the value 0, viewdf will always show "0" for the frequencies of that level and then shift all the other frequencies by one (i.e., the frequencies of "0" are displayed where the "1" is, the frequencies of "1" are displayed where the "2" is, and the frequencies of the last value are omitted).
For an example, see this variable that I recoded to start with 0
I can replicate this issue by merely recoding a variable so that the starting value is 0.
The text was updated successfully, but these errors were encountered: