How to use `assign()` or `get()` on specific named column of a dataframe?
问题 Is there a way to assign a value to a specific column within a data frame? e.g., dat2 = data.frame(c1 = 101:149, VAR1 = 151:200) j = "dat2[,"VAR1"]" ## or, j = "dat2[,2]" assign(j,1:50) The approach above doesn't work. Neither does this: j = "dat2" assign(get(j)[,"VAR1"],1:50) 回答1: lets assume that we have a valid data.frame with 50 rows in each dat2 <- data.frame(c1 = 1:50, VAR1 = 51:100) 1 . Don't use assign and get if you can avoid it. "dat2[,"VAR1"]" is not valid in R . You can also note