【问题标题】:R not identifying column headers as object- data read from xlsxR没有将列标题识别为从xlsx读取的对象数据
【发布时间】:2020-03-24 09:02:39
【问题描述】:

我正在学习在 r 中运行线性回归。 我有一个使用 read.xl 函数读入的简单数据集。 我得到的列名很好,但它们没有被识别为对象,所以我不能对它们做任何事情。 我的列标题是 Cooper_score 和 VO2max。

library(readxl)
library(ggplot2)
Cooper <- read_xlsx("R_Learning/Cooper.xlsx", sheet=1)
View(Cooper)
colnames(Cooper)

这个位工作正常,但是当我尝试以下任何一个时,我得到一个错误

plot(Cooper_score,VO2max,xlab="Cooper Score", ylab="VO2(max)(ml/kg/min)")
cor(Cooper_score,VO2max)
simple_reg_cooper <- lm(VO2max ~ Cooper_score)
summary(simple_reg_cooper)

例如

绘图错误(Cooper_score, VO2max, xlab = "Cooper Score", ylab = "VO2(max)(ml/kg/min)"): 找不到对象“Cooper_score”

相关和线性回归函数也是如此

【问题讨论】:

    标签: r excel object linear-regression


    【解决方案1】:

    要访问数据框中的列,请使用 $ 符号,例如Cooper$score 将访问名为 score 的列(区分大小写)。

    【讨论】:

    • 非常感谢。列名是Cooper_score。所以Cooper$Cooper_score 成功了
    猜你喜欢
    • 1970-01-01
    • 2014-07-02
    • 2015-05-13
    • 1970-01-01
    • 2010-11-13
    • 2019-08-18
    • 2017-05-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多