错误消息 - 为什么显示“未找到对象”?
我对 R 和 stackoverflow 非常陌生,所以如果我以某种方式违反了任何礼仪,我会提前道歉。
到目前为止,我只按照书籍教程输入了几行代码。这本书是 Statistical Modeling: A Fresh Approach,出版于 2012 年,所以我不确定它有什么版本的 R。我正在使用 R 4.0.0。
到目前为止我所写的是:
cherryBlossom2008 <- read.csv("Cherry-Blossom-2008.csv")
names(cherryBlossom2008)
这会产生:
[1] "position" "division" "total" "name" "age" "place" "net" "gun" "sex"
接下来我输入:
mean(age, data=cherryBlossom2008)
我立即收到一条错误消息,上面写着:
Error in mean(age, data = cherryBlossom2008) : object 'age' not found
我不确定这是怎么可能的。 “年龄”是在cherryBlossom2008中。我的书说,如果我在使用“mean”命令时未能定义“data”,我会收到该错误消息,但正如你所看到的,我确实定义了“data”,所以我没有了解我如何定义“年龄”。
I'm very new to R and stackoverflow, so I apologize ahead of time if I'm breaking any etiquette somehow.
I have only typed a few lines of code so far, following a book tutorial. The book is Statistical Modeling: A Fresh Approach, printed in 2012, so I'm not sure what version of R it has. I am using R 4.0.0.
All I have written so far is:
cherryBlossom2008 <- read.csv("Cherry-Blossom-2008.csv")
names(cherryBlossom2008)
this produces:
[1] "position" "division" "total" "name" "age" "place" "net" "gun" "sex"
Next I typed:
mean(age, data=cherryBlossom2008)
I immediately get an error message that says:
Error in mean(age, data = cherryBlossom2008) : object 'age' not found
I'm not sure how this is possible. 'age' is in cherryBlossom2008. My book says that I would get that error message if I failed to define "data" when using the "mean" command, but as you can see I did define "data", so I don't understand how else I would define 'age'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有提到这本书,所以我可能会在这里失去一些上下文,但根据你的解释和描述,我认为这里的可能性很小。
mean
是一个内部命令。您可以查看文档 (?mean
) 并注意到mean
中没有定义data
参数。要获得
mean
你可以使用 -你应该使用其他库中存在的
mean
命令,而不是基础库。您必须定义自己的
mean
函数,而不是使用内部函数。在这种情况下 -
mean(age, data=cherryBlossom2008)
将起作用。例如 - 使用
mtcars
数据集 -然而,这个选项不太可能。
I haven't referred the book so I may be loosing some context here but based on your explanation and description I think there are few possibilities here.
mean
is an internal command. You can look at the documentation (?mean
) and notice there is nodata
argument defined inmean
.To get
mean
you can use -You are supposed to use
mean
command present in some other library and not base.You have to define your own
mean
function and not use the internal one.In which case -
mean(age, data=cherryBlossom2008)
will work.For eg - with
mtcars
dataset -However, this option is very unlikely.