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

3

1 Answer

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.

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.