问题 Say I have the following data frame: # Set seed for RNG set.seed(33550336) # Create toy data frame loc_x <- c(a = 1, b = 2, c = 3) loc_y <- c(a = 3, b = 2, c = 1) scaling <- c(temp = 100, sal = 10, chl = 1) df <- expand.grid(loc_name = letters[1:3], variables = c("temp", "sal", "chl"), season = c("spring", "autumn")) %>% mutate(loc_x = loc_x[loc_name], loc_y = loc_y[loc_name], value = runif(nrow(.)), value = value * scaling[variables]) which looks like, # > head(df) # loc_name variables