I would like to loop through v1 to v3 and dividing them by weight column, but I have issues in the loop (in real life the variables have different names)
Name <- c("Jon", "Bill", "Maria", "Ben", "Tina")
v1 <- c(23, 41, 32, 58, 26)
v2 <- c(13, 41, 35, 18, 66)
v3 <- c(3,34, 33, 34, 23)
weight <- c(2, 4, 3, 5, 6)
df <- data.frame(Name,v1,v2,v3,weight)
print (df)
for(i in 2:4 (df)) { # for-loop over columns
df[ , i] <- df[ , i] /df$weight
}