However, when I replicated the same code using a Windows notebook, it just shows me a bunch of html code. I tried on both console and .RMD file, none of then worked.
Does anyone knows why this is happening just with rstudio on Windows? I have both RStudio and Windows updated.
Thank you!
# code from M.Devlin tutorial described above
[Tables and Plots of Counts and Proportions](https://rstudio-pubs-static.s3.amazonaws.com/80278_2a7b4c5561394b04ad3f135d89421919.html)
library(tidyverse)
library(ztable) #format tables for reporting
dfr <- mtcars %>%
mutate(cyl = as.factor(cyl)
, gear = as.ordered(gear))
dfr_prop <- dfr %>%
count(cyl, gear) %>%
mutate(prop = prop.table(n))
as.data.frame(dfr_prop)
dfr_perc <- dfr %>%
count(cyl, gear) %>%
mutate(perc = prop.table(n)*100) %>%
select(-n) %>%
spread(gear, perc)
dfr_dist <- dfr %>%
count(cyl) %>%
mutate(`(\\%)` = prop.table(n)*100) %>%
left_join(dfr_perc, by = 'cyl')
### 1 digit to distinguish % from n and caption
ztab <- ztable(as.data.frame(dfr_dist), digits = 1
, caption = 'Distribution of Gears by Cylinders')
### name and number column groups
ztab <- addcgroup(ztab, cgroup = c('Cylinders', 'Gear Distribution (\\%)')
, n.cgroup = c(3, ncol(dfr_dist)-3))
### when I try this on Windows it just shows a bunch of html code
ztab
Consider editing the title (cross tabulation is working fine, the problem seems to lie in how the RStudio IDE Viewer is rendering the styled HTML output).
Sometimes half the problem is figuring out the right search term! The auto-rendering that the RStudio IDE does is magically helpful when all goes well, but can sure be confusing when you run into trouble.
If you do find an answer on SO, you should link to it here for everyone's benefit! And if you wind up posting a new question on SO, definitely say so here (to abide by this community's cross-site posting policy).