【发布时间】:2021-04-19 16:50:47
【问题描述】:
在 R 包中编写函数时,为什么更喜欢使用以下方法之一来引用 data.frame 中的列?
d <- data.frame(x = c(1, 2))
# This is one way to extract a column from a data.frame.
# Using dollar sign notation
d$x
#> [1] 1 2
# This is another way to extract a column from a data.frame
d[["x"]]
#> [1] 1 2
由reprex package (v1.0.0) 于 2021-04-19 创建
我隐约记得读到第二种方法在使用 R 编程时更可取,但我不记得为什么。美元符号方法更简洁,所以在其他条件不变的情况下,我宁愿使用美元符号方法。
【问题讨论】: