error with as.factor()


I'm working on an assessment for university. I have load tidyverse, and imported the data using read() to assign directly in the environment.

To explore the data I have used glimpse() and realised some variable needs to be changed. e.g., Camp_1 are dbl and I want to change to factor.

in all of our practices, we had to change to a factor.

to change it I did:
sales <- sales %>%
mutate_(sales, Camp_1=as.factor(Camp_1),

however I get the following message: Error in is.factor(x) : object 'Camp_1' not found

I don't understand the mistake I have made. If someone has an idea it would be very useful.


mutate is a different function from mutate_ try to swap that out.

Thank you now it works.

Now I'm trying to create a plot: ggplot(general_sales, aes(x=Campaign, y=general_sales))+
geom_col(fill="green", alpha=1)

but it says errors:
#Visual for General Sales with ggplot

ggplot(general_sales, aes(x=Campaign, y=general_sales))+

  • geom_col(fill="green", alpha=1)
    Don't know how to automatically pick scale for object of type tbl_df/tbl/data.frame. Defaulting to continuous.
    Error in check_aesthetics():
    ! Aesthetics must be either length 1 or the same as the data (994): y
    Run rlang::last_error() to see where the error occurred.

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.