【问题标题】:Undefined columns error when referencing element of data.frame引用 data.frame 的元素时出现未定义的列错误
【发布时间】:2019-01-17 23:35:33
【问题描述】:

我正在尝试绘制许多图表,但在引用 data.frame 的元素时出现错误。

我不想手动更改变量名称,而是要循环并引用特定的变量名称。

当我这样做时,我得到“未定义的列已选择”错误。

当我运行这段代码时,我得到了正确的情节:

xy <- lm(Unfairness_Scale ~ OS_ImpCoreV_A * ImpCoreV_A, data = 
branch_annual)
with(branch_annual, interact_plot(xy, pred = OS_ImpCoreV_A, modx = 
ImpCoreV_A))

当我运行此代码时,我收到“未定义的列已选择”错误:

xy <- lm(branch_annual$Unfairness_Scale ~ branch_annual$OS_ImpCoreV_A * 
branch_annual$ImpCoreV_A, data = branch_annual)
with(branch_annual, interact_plot(xy, pred = branch_annual$OS_ImpCoreV_A, 
modx = branch_annual$ImpCoreV_A)) 

我尝试了几种不同的方法来引用数据框的元素,但我一直收到同样的错误。我没有正确理解什么?

谢谢,

塞巴斯蒂安

【问题讨论】:

  • 请提供reproducible example,很难看出您的问题是什么/您想要什么。哪一行给出了错误? lm 还是 interact_plotinteract_plot 哪里来的?

标签: r dataframe


【解决方案1】:

您可以将as.formula 与字符一起用作循环的输入,并在 lm 函数中构造公式。

xy <- lm(as.formula(paste('Unfairness_Scale', '~', 'OS_ImpCoreV_A', '* 
', 'ImpCoreV_A')), data = branch_annual)
with(branch_annual, interact_plot(xy, pred = 'OS_ImpCoreV_A', 
modx = 'ImpCoreV_A')) 

【讨论】:

    猜你喜欢
    • 2020-10-04
    • 2018-11-27
    • 2019-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-27
    • 1970-01-01
    相关资源
    最近更新 更多