在R中使用字典/列表 [英] Working with dictionaries/lists in R

查看:807
本文介绍了在R中使用字典/列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个微不足道的问题:我找不到R中的字典数据结构,所以我用list来代替(比如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, right now I have problem how to get the list of keys. Anybody knows?

推荐答案

是的, list type是一个很好的近似值。您可以在列表中使用 names()来设置和检索'keys':

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"
> 

这篇关于在R中使用字典/列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆