How to convert date column which is in class "character'' into a date class.

Hi there....
I have tried the hms() and I got the results. I have a few doubts here

1)Did you choose hms() from lubridate?

2)What is "x" here?

  1. The output result in a few rows is like this 80:45:00 and in some other outputs if the original time is 946 the output result was 94:60:00.(working as per the code)..something is wrong here

  2. Are R base and Rstudio the same or are they both different?

Please clarify my doubts...Thank you.

  1. The hms() function if from the hms package. You can see that my code starts with library(hms).
  2. x is just the argument of the TimeConvert function that I wrote. Running TimeConvert(DF$schedtime) is the same as running TimeConvert(x = DF$schedtime)
    I could have used a more informative name for the argument, like this
TimeConvert <- function(TimeValue) {
  hms(seconds = rep(0, length(TimeValue)), 
      minutes = as.numeric(substr(TimeValue, 3, 4)), 
      hours = as.numeric(substr(TimeValue, 1, 2)))
}
  1. I wrote the TimeConvert function using a bad assumption. Here is a better version that uses interger division and the modulo function to calculate the hour and minutes.
TimeConvert <- function(x) {
  hms(seconds = rep(0, length(x)), 
      minutes = x %% 100, 
      hours = x %/% 100)
}
  1. R and RStudio are separate software. R is the programming language that does the data handling, calculations, plotting, etc. Base R is what you get when you run R without using any additional packages. RStudio is the software that presents the graphical user interface and all the helpers that provide things like the four panes displaying information, autocomplete when you start to type a function, and shortcut keys for inserting certain symbols. You can run R without RStudio, but it is less convenient.

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.