According to your approach by using group_by
and summarise
, which can be changed as:
df_summed <- df %>%
group_by(sample) %>%
summarise(
across(starts_with("var"), first), # Keep first value of abiotic variables
across(starts_with("species"), sum) # Sum the species abundance values
)