pavan
pavan

Reputation: 1

Applying select() to create new data frame with three variables

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_ -> -> lapply -> FUN -> eval -> eval

I tried this and that and final exhausted for not finding the answer. Please help me

Upvotes: 0

Views: 5545

Answers (1)

Sage Wyatt
Sage Wyatt

Reputation: 51

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.

Upvotes: 1

Related Questions