R 连接变量名(内部循环)

R 连接变量名(内部循环),r,concatenation,R,Concatenation,在我的data.frame中,我想在循环中自动添加一些变量。例如“abc_1”、“abc_2”、“abc_3” data.frame: x <- c(1,2,3) y <- c(4,5,6) test<- data.frame("V1"=x, "V2"=y) x我们可以在不使用for循环的情况下执行此操作 test[paste0("abc", 1:3)] <- 5 test[paste0(“abc”,1:3)]也许你需要[或者可能是test[paste0(“abc,1

在我的data.frame中,我想在循环中自动添加一些变量。例如“abc_1”、“abc_2”、“abc_3”

data.frame:

x <- c(1,2,3)
y <- c(4,5,6)
test<- data.frame("V1"=x, "V2"=y)

x我们可以在不使用
for
循环的情况下执行此操作

test[paste0("abc", 1:3)] <- 5

test[paste0(“abc”,1:3)]也许你需要
[
或者可能是
test[paste0(“abc,1:3)]完美的,谢谢!还在弄清楚如何以及何时使用括号;)
test[paste0("abc", 1:3)] <- 5