с data.table
это было бы что-то вроде:
library(data.table)
dat <- data.table(Year = c(2016, 2016, 2015), TF = c("Import", "Export", "Export"), value = c(123, 456, 789))
dat[, .(`total export` = sum(value[TF == "Export"]), `total import` = sum(value[TF == "Import"]), total = sum(value)), by = Year]