Hello,
I always have issues with pivot_wider or pivot_longer
I have a data frame with mutation status and group:
data.frame(KRAS = c("M","NM","NM","M"),EGFR=c("M","NM","M","NM"),TP53=c("NM","M","M","NM"), group = c("1","2","3","1"))
I would like a final dataframe with the number of mutations for each group :
The pivot functions are very powerful yet indeed sometimes tricky to wrap your head around. In your example however, you can't solve the issue by just using one pivot function, rather you want to carry out a summary across the columns per group. So that would translate to this