R,如何使用变量的内容作为列表字段的名称?

R, how to use the content of a variable as the name of a field of a list?

我在 and I would like to allocate a 字段中工作,该字段具有变量内容的名称。在下面的示例中,我希望列表 this_list 的一个字段被称为 bbb 并且具有值 2,但是我通过同时使用 paste()eval(quote()):

var <- "bbb"

this_list <- list()
this_list$aaa <- 1

this_list$paste(var) <- 2
Error: attempt to apply non-function

this_list$eval(quote(var)) <- 2
Error: attempt to apply non-function

我想要的输出是:

str(this_list)
List of 2
 $ aaa: num 1
 $ bbb: num 2

有人可以帮助我并告诉我正确的命令使用吗?谢谢!

而不是$,使用[[评估对象

this_list[[var]] <- 2
this_list
#$aaa
#[1] 1

#$bbb
#[1] 2