I am for sure no expert in R yet. I grew up with SPSS and is slowly shifting to R. I solve problems as I meet them. And seek help when I get lost.
Please look at this code:
dataset$v18[dataset$s_18 == 1] <- "Agree"
dataset$v18[dataset$s_18 == 2] <- "Partly Agree"
dataset$v18[dataset$s_18 == 3] <- "Neutral"
dataset$v18[dataset$s_18 == 4] <- "Partly disagree"
dataset$v18[dataset$s_18 == 5] <- "Disagree"
sv18x <- dataset %>%
filter(!is.na(v18)) %>%
group_by(v18) %>%
dplyr::summarise(count=n()) %>%
mutate(pct=count/sum(count)*100)
sv18x$v18 <- factor(sv18x$v18,levels = c("Agree", "Partly agree", "Neutral", "Partly disagree", "Disagree uenig"))
sv18x$pct<- trunc(sv18x$pct)
I feel quite confident what this can be done in a shorter and smarter way. And I think it should be done using dplyr::recode() and something else that I probably don't know yet. I just can't figure out how to do it. Can someone give me a hint?