Finding solution to mutate error message

Riding_time

Hi everyone,

I tried running the below codes and I'm getting an error message. Checking if anyone can help prefer a solution. Looking forward to your feedback. Thanks!

Code:

clean_dfs <- new_binded_dfs_no_dups
clean_dfs <- clean_dfs %>%
  mutate(riding_time = as.numeric(end_hours-start_hours)/60)

clean_dfs 

Error Message:
Error in mutate(): ! Problem while computing riding_time = as.numeric(end_hours - start_hours)/60. Caused by error: ! object 'end_hours' not found Backtrace: 1. clean_dfs %>% ... 3. dplyr:::mutate.data.frame(...) 4. dplyr:::mutate_cols(.data, dplyr_quosures(...), caller_env = caller_env()) 6. mask$eval_all_mutate(quo)

[image] Show Traceback

Error in mutate(., riding_time = as.numeric(end_hours - start_hours)/60) : Caused by error: ! object 'end_hours' not found.

Note:
Kindly note that I had previously created the 'start_hours' & 'end_hours' columns using the below codes:

Start_hours & End_hours

clean_dfs <- clean_dfs %>%
  mutate(start_hours=strftime(clean_dfs$started_at, format = "%H:%M:%S",tz = "UTC"))

clean_dfs <- clean_dfs %>%
  mutate(end_hours=strftime(clean_dfs$ended_at, format = "%H:%M:%S",tz = "UTC"))
clean_dfs

Hi,

Welcome to the RStudio community!

It would be easier to find the source of this error if you could provide us with a reprex. A reprex consists of the minimal code and data needed to recreate the issue/question you're having. You can find instructions how to build and share one here:

The error now occurs because there is no end_hours in your data frame, but you show below you create this using the clean_dfs mutate. However, this line seems problematic:

clean_dfs <- new_binded_dfs_no_dups

You overwrite the clean_dfs with data from another variable, so even if you did change it before, it will revert to this one (and thus lose the mutated variables probably).

Please provide a reprex if this is not the issue
PJ

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.