【问题标题】:List of hashmaps in RR中的哈希图列表
【发布时间】:2021-01-07 23:22:41
【问题描述】:

我正在尝试在 R 中创建一个哈希列表,但我还没有弄清楚。

我知道在 python 中我可以做到

d1 = { id: 1, name: 'ada' }
d2 = { id: 2, name: 'bob' }
users = list()

users.append(d1)
users.append(d2)

有没有办法在 R 中做类似的事情? 其他选项可能只是一个列表列表并通过索引访问它们。

【问题讨论】:

    标签: python r list dictionary hashmap


    【解决方案1】:

    根据您的具体用例,使用数据框可能更容易:

    df <- data.frame(
            id = c(1, 2),
            name = c("ada", "bob"),
            stringsAsFactors = FALSE)
    

    值可以引用为:

    df$name[df$id == 1]   # answer "ada"
    

    【讨论】:

      猜你喜欢
      • 2023-03-31
      • 2013-06-25
      • 2013-03-21
      • 1970-01-01
      • 1970-01-01
      • 2015-12-21
      • 1970-01-01
      • 2016-08-29
      • 1970-01-01
      相关资源
      最近更新 更多