Error: no applicable method for 'mutate_' applied to an object of class "character"

Hi all, I get an error on the last step of this code. The other two times I used mutate() it worked. The last time though, the column "KeepFinal" does not get created and gives the following error: Error in UseMethod("mutate_") : no applicable method for 'mutate_' applied to an object of class "character"

R script follows:


GSoff_serv <- PreScFilter %>% 
  arrange(GSoffered) %>% 
  select(Concatenate, OpenDate, EILName, GSoffered, GSserved) %>% 
  mutate(KeepOff=ifelse(GSoff_serv$GSoffered=="K" | GSoff_serv$GSoffered=="K-1" | GSoff_serv$GSoffered=="K-3" | GSoff_serv$GSoffered=="K-4", "N", "Y")) %>%
  mutate(KeepSer=ifelse(GSoff_serv$GSserved=="K" | GSoff_serv$GSoffered=="K-1" | GSoff_serv$GSoffered=="K-3" | GSoff_serv$GSoffered=="K-4", "N", "Y")) %>%
  GSoff_serv$KeepSer[$KeepSer)] <- "Y" %>%
  mutate(KeepFinal=ifelse(GSoff_serv$KeepOff=="N" & GSoff_serv$KeepSer=="N", "No", "Yes"))

Are you sure that this is what you want to do? You are trying to use mutate call on a string "Y" and therefore getting the error you are getting.

In general, it is much easier to help you if you can put your question into reprex. You can find out more about what it is and how to do it here:

1 Like

@mishabalyasin Thank you, I wanted to create 3 new variables but needed to get rid of the NAs in order to create the last variable. If there something I should do differently, please advise. I do not think I want to use mutate call on a string "Y"... but I wanted to try to do it all in one go. It is my second day working with pipes. I will also look into the reprex link, thank you.