Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 R 列表中,我可以设置列表成员名称
> l = list() > l$a = 1:10 > l $a [1] 1 2 3 4 5 6 7 8 9 10
但是,如何从字符串变量中设置列表成员名称?喜欢
> var_name = "a" > l = list() > l$var_name <- 1:10 > l $var_name [1] 1 2 3 4 5 6 7 8 9 10
使用[[而不是怎么样$?
[[
$
> l[[var_name]] <- 1:10 > l $a [1] 1 2 3 4 5 6 7 8 9 10