In my dataset, the duration of a activity is either given in hours (column duration_hours
) or in minutes (column duration_minutes
). If it is given in hours, the duration_minutes
column is empty (NA
) and vice versa.
I now want to convert the values given in minutes into hours by dividing them by 60 (minutes).
To do so I tried this command:
df <- df %>% mutate(duration_recoded = replace(duration_minutes, !is.na(duration_minutes), duration_minutes / 60))
However, the command produces incorrect results and this warning message is shown:
Warning message:
In x[list] <- values :
number of items to replace is not a multiple of replacement length
Can anybody tell me where my mistake is?
Here's some sample data:
df <- structure(list(duration_hours = c(1, NA, 2, NA, 1), duration_minutes = c(NA, 25, NA, 30, NA)), row.names = c(NA, -5L), class = c("tbl_df", "tbl", "data.frame"))