【发布时间】:2017-07-02 11:25:21
【问题描述】:
我知道从作为参数传递给函数的对象中获取名称的 deparse+substitute 技巧,但循环内的相同技巧不起作用。
我的代码(仅用于测试):
mylist <- list(first = c("lawyer","janitor"), second = c("engineer","housewife"))
for (element in names(mylist)){
print(deparse(substitute(mylist[[element]])))
}
[1] "mylist[[element]]"
[1] "mylist[[element]]"
有没有办法得到结果?:
first
second
【问题讨论】:
-
在你的例子中你可以使用
print(element).. -
names(mylist)有什么问题?
标签: r