1

I'm extremely new to R, and I am using it to analyze a massive data set. Currently my variable B4S1 looks like this (e.g., 10:30, 11:00, 9:45), and I need it to look like this (e.g., 10.5, 11, 9.45). I tried really hard to figure out how to accomplish this, but I don't really understand what is going in the strptime function. Here is what I have...

SleepTime <- (usedata$B4S1)
SleepTime <- as.character(SleepTime)
sapply(strsplit(SleepTime,":"),
  function(x) {
    x <- as.numeric(x)
    x[1]+x[2]/60
    }
)

If there are obvious mistakes it would be extremely helpful if you could point them out and tell me where I'm going wrong. Being new at this, I don't fully have a grasp on what I'm doing. Thanks a bunch! :)

  • See also [R How to convert time to decimal](http://stackoverflow.com/questions/21781311/r-how-to-convert-time-to-decimal) – Henrik Feb 11 '17 at 21:30
  • There are 1,200 participants, so I'm not exactly sure how to share the data. However, when I run it with the data I get this error message "Warning message: 1: In FUN(X[[i]], ...) : NAs introduced by coercion 2: In FUN(X[[i]], ...) : NAs introduced by coercion – Marieke Visser Feb 11 '17 at 21:30

0 Answers0