[英]R: Error in eval(predvars, data, env) : object 'x' not found
I am quite new to R, so this might seem like a really simple question.我对 R 很陌生,所以这似乎是一个非常简单的问题。 However I don't know specifically what to search for because I don't really know what is causing the problem.但是我不知道具体要搜索什么,因为我真的不知道是什么导致了问题。 Both CSV-files mentioned below are formatted in the same way, which is the reason I don't know what is causing the trouble.下面提到的两个 CSV 文件都以相同的方式格式化,这就是我不知道是什么导致问题的原因。 However the CSV that is returning the error mentioned below has many more rows than the other.但是,返回下面提到的错误的 CSV 的行数比另一个多得多。
I have a certain dataset I want to run a linear model on (lm in R).我有一个特定的数据集,我想在(R 中的 lm)上运行线性模型。 I imported it into R from a CSV using this code in R:我使用 R 中的以下代码将其从 CSV 导入到 R 中:
rawData=read.csv("dataset.csv", header=T) rawData=read.csv("dataset.csv", header=T)
When requesting an output of the ten top rows by we get:当请求输出前十行时,我们得到:
> head(rawData, 10)
ï..x y
1 1 0.0
2 2 0.0
3 3 0.0
4 4 0.0
5 5 0.0
6 6 0.5
7 7 0.0
8 8 0.0
9 9 0.1
10 10 0.0
From the above output we see that the top row display as follows:从上面的输出中我们看到顶行显示如下:
ï..x y
Running a linear model on the last one returns an error messages:在最后一个上运行线性模型会返回错误消息:
simple.fit = lm(x~y, data=dataset)
summary(simple.fit)
The error message returned is:返回的错误信息是:
Error in eval(predvars, data, env) : object 'x' not found
How can this be solved?如何解决?
As we can see below the output from an import of another CSV file (I just used for testing linear regression) in R the output is as follows:正如我们在下面看到的,在 R 中导入另一个 CSV 文件(我只是用于测试线性回归)的输出如下所示:
> rawData=read.csv("testing.csv", header=T)
> head(rawData, 10)
x y
1 82.58321982 134.907414
2 73.92246618 134.085180
3 34.88744536 NA
4 61.83998269 114.530638
5 16.77594025 31.376437
6 0.01673734 8.764634
7 44.45764646 73.285341
8 10.34490930 18.859865
9 42.76713229 72.946609
10 20.85663802 28.637286
Here we see the top row have simply:在这里,我们看到顶行很简单:
x y
Running a linear model on the last one returns no error messages and gives an output simple.fit = lm(x~y, data=testing) summary(simple.fit)在最后一个上运行线性模型不会返回错误消息并给出输出 simple.fit = lm(x~y, data=testing) summary(simple.fit)
对于这种情况,您可以尝试使用 library janitor
中的clean_names()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.