使用字典/列表来获取键列表 [英] Working with dictionaries/lists to get list of keys
本文介绍了使用字典/列表来获取键列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个小问题:我在 R 中找不到字典数据结构,所以我改用列表(如 >word>number
).那么,如何获取键列表.
I have trivial question: I couldn't find a dictionary data structure in R, so I used list instead (like "word"->number
).
So, how do I get the list of keys.
推荐答案
是的,list
类型是一个很好的近似值.您可以使用列表中的 names()
来设置和检索键":
Yes, the list
type is a good approximation. You can use names()
on your list to set and retrieve the 'keys':
> foo <- vector(mode="list", length=3)
> names(foo) <- c("tic", "tac", "toe")
> foo[[1]] <- 12; foo[[2]] <- 22; foo[[3]] <- 33
> foo
$tic
[1] 12
$tac
[1] 22
$toe
[1] 33
> names(foo)
[1] "tic" "tac" "toe"
>
这篇关于使用字典/列表来获取键列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文