简体   繁体   English

eval(predvars,data,env)中的错误:找不到对象

[英]Error in eval(predvars, data, env) : object not found

I have a problem with a nested data frame on R. I used gapminder for an exercise, I followed the code of the author of a Data Science book, which is the following: 我对R上的嵌套数据框有疑问。我使用gapminder进行了练习,我遵循了数据科学书的作者的代码,如下所示:

library(gapminder)

by_country <- gapminder %>% 
  group_by(country, continent) %>% 
  nest()

In that way the gapminder dataset is nested. 这样,gapminder数据集就被嵌套了。 There's only 1 row for each country and all data regarding that country is the the column 'data'. 每个国家/地区只有1行,而与该国家/地区有关的所有数据均在“数据”列中。

Then I created a function for mapping all the cells of the nested data frame. 然后,我创建了一个用于映射嵌套数据帧的所有单元格的函数。 Calling that function, each cell of the column 'data' will have a personal model. 调用该函数,“数据”列的每个单元格都会有一个个人模型。

country_model <- function(df) {
  lm(lifeExp ~ year, data = df)
}

In the end I tried to create a new column in the by_country dataset, by calling the previous function, but it says Error in eval(predvars, data, env) : object 'lifeExp' not found . 最后,我试图通过调用前一个函数在by_country数据集中创建一个新列,但是它说eval(predvars,data,env)中存在错误:找不到对象'lifeExp'

by_country <- by_country %>%
  mutate(model = map(data,country_model))

lifeExp is a column inside every cell of data, but it says it didn't find that. lifeExp是每个数据单元中的一列,但它说没有找到。 Honestly I don't understand where the problem is, can anybody help me, please? 老实说,我不明白问题出在哪里,请问有人可以帮我吗?

I encountered this error with a similar set of package versions, and after updating dplyr, tidyr, and purrr the code ran successfully. 我在使用一组相似的软件包版本时遇到了此错误,并且在更新dplyr,tidyr和purrr之后,代码成功运行了。

Showing truncated output from sessionInfo() for my session after loading only tidyverse, modelr, and gapminder. 仅加载tidyverse,modelr和gapminder之后,显示会话的sessionInfo()的截断输出。

Good luck! 祝好运!

other attached packages: [1] gapminder_0.3.0 modelr_0.1.2 forcats_0.3.0 stringr_1.4.0 dplyr_0.8.3 purrr_0.3.2 readr_1.1.1 tidyr_1.0.0
[9] tibble_2.1.3 ggplot2_3.2.0 tidyverse_1.2.1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 R:eval(predvars,data,env)中的错误:找不到对象&#39;x&#39; - R: Error in eval(predvars, data, env) : object 'x' not found 回归:评估错误(predvars,数据,env):未找到 object 'volt' - regression: Error in eval(predvars, data, env) : object 'volt' not found eval(predvars, data, env) 中的错误:找不到对象“下水道” - Error in eval(predvars, data, env) : object 'Sewer' not found eval(predvars, data, env) 中的错误:找不到对象“BMI” - Error in eval(predvars, data, env) : object 'BMI' not found eval(predvars, data, env) 中的错误:找不到对象“有用” - Error in eval(predvars, data, env) : object 'helpfulness' not found eval(predvars,data,env)中的systemfit错误:找不到对象 - systemfit Error in eval(predvars, data, env) : object not found stepcAIC-eval(predvars,data,env)中的错误:找不到对象&#39;Color1&#39; - stepcAIC - Error in eval(predvars, data, env) : object 'Color1' not found eval(predvars, data, env) 中的错误:找不到对象“Rm” - Error in eval(predvars, data, env) : object 'Rm' not found eval 中的错误(predvars、data、env):未找到 object 'Practice' - Error in eval(predvars, data, env) : object 'Practice' not found eval 中的错误(predvars、data、env):object 'Example' not found in RandomForest function - Error in eval(predvars, data, env) : object 'Example' not found in RandomForest function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM