应用select()函数创建包含三个变量的新数据框。

huangapple go评论69阅读模式
英文:

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 &lt;- flavors_df %&gt;% 

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 &lt;- flavors_df %&gt;% select(flavors_df, rating,cocoa.percent,bean.type)

What will work

trimmed_flavors_df &lt;- select(flavors_df, rating,cocoa.percent,bean.type)

or alternatively

trimmed_flavors_df &lt;- flavors_df %&gt;% select(rating,cocoa.percent,bean.type)

Notice removal of "flavors_df" from within the select() brackets, or without the pipe.

huangapple
  • 本文由 发表于 2023年5月11日 17:17:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76226021.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定