I need to create a prop.table column in a tibble object using dplyr.
However, I 'm not sure. Here is my data:
responses=c("yes","no","yes","no","yes","no") cases=c(100,500,200,600,400,1000) zone=c(1,1,2,2,3,3) data=data.frame(responses,zone,cases) data=as_tibble(data) data$responses=factor(data$responses) data data %>%group_by(zone) %>% mutate(percentage=cases/sum(cases))
I need to compute a prop.table considering yes/no response on every zone.
I noticed I couldn't use prop.table (It was complex for me).
Also, if I try to perform the same operation but using cases as integers, I obtain just "1" as result.
I need to convert It to dbl (with hablar) in order to gain the decimal places.
Anyway, does my code look ok?
Thanks for your time and interest.