I have used R Studio now for years and more often so than any other software, but now that I'm gioing to teach statistics with R, I realize that some tasks are just simpler using other software such as STATA.
Is there a simple way of getting a frequency table in R (including count, percent, and cumulative frequencies) just like we would get by typing tab [variable]
in STATA?
I came across this tidyverse solution:
dataset <- tribble(
~var1, ~var2, ~var3, ~var4, ~var5,
"1", "1", "1", "a", "d",
"2", "2", "2", "b", "e",
"3", "3", "3", "c", "f")
dataset %>%
group_by(var1) %>%
summarise(n = n()) %>%
mutate(totalN = (cumsum(n)),
percent = round((n / sum(n)), 3),
cumpercent = round(cumsum(freq = n / sum(n)),3))
But this is, very obviously, far to complicated to teach undergrads. Isn't there an easier way, maybe a base R solution even? Ideally, I would like to have one line of code for which I don't have to install 5-10 different packages first.