对命名为字符串的对象进行多次赋值
Making multiple assignments to objects named as strings
我们可以使用对象的名称为单个对象赋值 - assign("x", 1)
- 由于 zeallot
包,我们可以有效地将不同的值赋给多个对象 - c(x, y) %<-% c(1, 2)
- 但我们可以两者都做吗?我基本上只想做 c("x", "y") %<-% c(1, 2)
而且我只能想以这种可爱的方式去做:
invisible(mapply(function(i, j) assign(i, j, envir = .GlobalEnv), i = c("x", "y"), j = c(1, 2)))
有没有更好的办法?
您可以将列表的命名元素列出到环境中:
list2env(setNames(as.list(c(1,2)),c("x","y")),.GlobalEnv)
我们可以使用对象的名称为单个对象赋值 - assign("x", 1)
- 由于 zeallot
包,我们可以有效地将不同的值赋给多个对象 - c(x, y) %<-% c(1, 2)
- 但我们可以两者都做吗?我基本上只想做 c("x", "y") %<-% c(1, 2)
而且我只能想以这种可爱的方式去做:
invisible(mapply(function(i, j) assign(i, j, envir = .GlobalEnv), i = c("x", "y"), j = c(1, 2)))
有没有更好的办法?
您可以将列表的命名元素列出到环境中:
list2env(setNames(as.list(c(1,2)),c("x","y")),.GlobalEnv)