This is what my dataframe looks like
I have a dataframe of several columns and several rows per Participant_ID. I want to sum data for all lines of Participant_ID, to obtain one value per Participant_ID. The problem is that some columns are empty (all NAs), and for these columns I want to keep NA as a result. But when I sum with na.rm = T, it transforms the sum of NAs to 0.
I am using :
df = df %>%
group_by(Participant_ID) %>%
summarise(across(where(is.numeric), ~ sum(.x, na.rm = T)))
How can I exclude columns (after group_by) with only NAs ? Or filter columns (after group_by) that contain at least one numeric value ?
Thanks a lot for your help !!