0
  1. I want to create the following freq columns for the below df/table (clean_df_mut_counts)
  2. Get the 2nd highest frequency allele at each patient*gene

patient gene A_count C_count G_count T_count A_freq. C_freq G_freq C_freq

"ptp_1" "BRCA1" values. values values. values

"ptp_1" "BRCA2" values.

"ptp_2" "BRCA1"

"ptp_2" "BRCA2"

tried as below. was able to get the pivot_wider to work which gave result as below-

clean_df_mut_counts_wide <- clean_df_mut_counts %>%  pivot_wider(
  names_from = base,
  values_from = count
)

result of above code-

enter image description here

clean_df_mut_counts_wide %>% 
    group_by(A, T, C, G) %>% 
      summarise(n = n()) %>% 
        mutate(freq= n/sum(n)) %>%
            top_n(n=2)

result of above code- enter image description here

analog_kid
  • 13
  • 3

0 Answers0