I have the following data frame and vector:
dframe <- as.data.frame(matrix(1:9,3))
vector <- c(2,3,4)
I would like to multiply each column of dframe
by the corresponding value of vector
. This won't do:
> vector * dframe
V1 V2 V3
1 2 8 14
2 6 15 24
3 12 24 36
each row of dframe
is multiplied by the corresponding value of vector
, not each column. Is there any idiomatic solution, or am I stuck with a for
cycle?