I have a data frame where one column is species\' names, and the second column is abundance values. Due to the sampling procedure, some species appear more than once (i.e.,
A data.table solution for time and memory efficiency
library(data.table)
DT <- as.data.table(df)
# which columns are numeric
numeric_cols <- which(sapply(DT, is.numeric))
DT[, lapply(.SD, sum), by = x, .SDcols = numeric_cols]
Or, in your case, given that you know that there is only the 1 column y you wish to sum over
DT[, list(y=sum(y)),by=x]