【发布时间】:2011-06-05 11:25:14
【问题描述】:
我有一个如下所示的 R 列表
> str(prices)
List of 4
$ ID : int 102894616
$ delay: int 8
$ 47973 :List of 12
..$ id : int 47973
..$ index : int 2
..$ matched: num 5817
$ 47972 :List of 12
..
显然,我可以通过例如访问任何元素价格$"47973"$id。
但是,我将如何编写一个函数来参数化对该列表的访问?例如带有签名的访问函数:
access <- function(index1, index2) { .. }
可以如下使用:
> access("47973", "matched")
5817
这似乎很琐碎,但我没有编写这样的函数。感谢您的任何指点。
【问题讨论】: