Applying Select() to Create New Data Frame with Three Variables

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

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

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.

Chloe Bennett
Author

Chloe Bennett

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.