更新时间:2021-12-25 05:14:24
与python字典最接近的东西R只是一个列表。与大多数R数据类型一样,列表可以具有一个名称属性,该属性可以使列表像一组名称/值对一样起作用:
The closest thing to a python dict in R is simply a list. Like most R data types, lists can have a names attribute that can allow lists to act like a set of name-value pairs:
> l <- list(a = 1,b = "foo",c = 1:5)
> l
$a
[1] 1
$b
[1] "foo"
$c
[1] 1 2 3 4 5
> l[['c']]
[1] 1 2 3 4 5
> l[['b']]
[1] "foo"
现在通常的免责声明:它们不是完全相同。会有差异。因此,您将很失望,尝试使用与在python中使用字典完全相同的方式来实际使用列表。
Now for the usual disclaimer: they are not exactly the same; there will be differences. So you will be inviting disappointment to try to literally use lists exactly the way you might use a dict in python.