We can use sub. We match the pattern _, followed by one or more digits ( \\d+) to the end ( $) of the line, and replace it with ''.
names(df) <- sub('_\\d+$', '', names(df))
Or, as @David Arenburg mentioned, it can be one or more characters ( .*) after _(which will match patterns such as var1_1, var1_d3533etc.)
names(df) sub("_.*", "", df)
Or we use paste(comment by @jogo)
names(df) <- c("Ind", paste0("var", 1:100))
akrun source
share