I know it is a basic quaestion but couldnt find any solution to it. I want to multiply all columns of a dataframe by single column.
df1<-data.frame(F1=c(1
We can vectorize the multiplication by replicating the 'C' column
rep
df1 * C[row(df1)] # F1 F2 F3 #1 2.0 2.0 2.0 #2 5.0 5.0 5.0 #3 16.0 16.0 16.0 #4 4.5 4.5 4.5
Or use the rep explicitly
df1 * rep(C$C, ncol(df1))