I am trying to create a new column (CoinfectionSpecified) based on if one of various viruses (I've specified the column indices) is detected (binary 0,1) in the sample AND the Influenza column is positive (binary 0,1). In CoinfectionSpecified, I want to list the virus detected with Influenza and separated by commas if there is more than one. I've been trying to wrap apply functions into if else statements but it keeps throwing out errors. e.g.
df <- df %>%
mutate(CoinfectionSpecified = ifelse(Influenza == 1 & rowSums(df[, column_indices] == 1) > 0,
paste(cols[df[, column_indices] == 1], collapse = ","),
NA_character_)
)