Skip to content
Prev 268777 / 398503 Next

Utilizing column names to multiply over all columns

You can simplify this a little with the sweep function:

sweep(mydf[, 1:3], 2, as.numeric(names(mydf)[1:3]), "*")

Hadley