英文:
Applying select() to create new data frame with three variables
问题
在预览和清理数据后,您确定哪些变量与您的分析最相关。您的主要关注点是评级、可可含量和豆类类型。您决定使用 select()
函数创建仅包含这三个变量的新数据框。
假设您的代码的第一部分是:
trimmed_flavors_df <- flavors_df %>%
添加能让您选择这三个变量的代码块。
我的代码:
select(flavors_df, rating, cocoa.percent, bean.type)
结果:
> Error in eval(expr, envir, enclos) : object 'rating' not found
Calls: %>% ... select_vars_ -> <Anonymous> -> lapply -> FUN -> eval -> eval
我尝试了这个和那个,最终感到筋疲力尽,找不到答案。请帮我。
英文:
After previewing and cleaning your data, you determine what variables are most relevant to your analysis. Your main focus is on Rating, Cocoa.Percent, and Bean.Type. You decide to use the select()
function to create a new data frame with only these three variables.
Assume the first part of your code is:
trimmed_flavors_df <- flavors_df %>%
Add the code chunk that lets you select the three variables.
My code :
select(flavors_df, rating,cocoa.percent,bean.type)
Result:
> Error in eval(expr, envir, enclos) : object 'rating' not found
Calls: %>% ... select_vars_ -> <Anonymous> -> lapply -> FUN -> eval -> eval
I tried this and that and final exhausted for not finding the answer. Please help me
答案1
得分: 1
以下是已翻译的部分:
不起作用的示例:
trimmed_flavors_df <- flavors_df %>% select(flavors_df, rating, cocoa.percent, bean.type)
有效的示例
trimmed_flavors_df <- select(flavors_df, rating, cocoa.percent, bean.type)
或者
trimmed_flavors_df <- flavors_df %>% select(rating, cocoa.percent, bean.type)
请注意,在select()括号内或不使用管道时,已删除“flavors_df”。
英文:
You can also make sure that you're not repeating a call for the dataframe twice, for example...
What will not work:
trimmed_flavors_df <- flavors_df %>% select(flavors_df, rating,cocoa.percent,bean.type)
What will work
trimmed_flavors_df <- select(flavors_df, rating,cocoa.percent,bean.type)
or alternatively
trimmed_flavors_df <- flavors_df %>% select(rating,cocoa.percent,bean.type)
Notice removal of "flavors_df" from within the select() brackets, or without the pipe.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论