Hi everyone.
I have a table which looks like the 1st 3 columns below. I wanted to add two more columns. The fourth column is the total for each age_group and the last the proportion (2 dp) (3rd column/4th column). Not sure how do do it.
Thanks.
library(tidyverse) (madeupdf <- data.frame(c=rep(0:3,2), a = sort(rep(letters[1:2],4)), n = 1:8 *10)) (total_df <- group_by(madeupdf, a) %>% summarise( total=sum(n) )) (result_df <- left_join(madeupdf, total_df) %>% mutate(prop = round(n/total,2)))
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.