I am currently trying to make a table with percentages after having used the pivot.wider command on a variable. htrisk is the datafile and menopaus and invasive are variables. Using the following code:
p_t <- htrisk %>%
group_by(menopaus, invasive) %>%
count(invasive, name = "n") %>%
pivot_wider(names_from = invasive, values_from = n, values_fill = 0)
pivot_test
Current table with wanted changes
I get the table above which is what I want, but I want to add two percentage columns which show the percents for let's say pre-meno/no and pre-meno/yes. Then for post-meno/no and post-meno/yes.
I have tried using the prop.table but I get the error "Error in FUN(X[[i]], ...) : only defined on a data frame with all numeric-alike variables".
Any help or direction would be much appreciated!