-1

I'm using an Excel dataset where the time values, MM:SS, come in numeric values that I need to convert to POSIXct in r and then make calculations.

Below is sample data of what I have and I need to get

dfOrig <- data.frame(StandarTime =  c(615,735,615 ),
                 AchievedTime =  c(794,423,544 ))

This is what I'm looking for:

dfCleaned <- data.frame(StandarTime =  c("2017-08-25 10:15",
                                     "2017-08-25 12:15",
                                     "2017-08-25 10:15" ),
                    AchievedTime =  c("2017-08-25 13:14 PDT",
                                      "2017-08-25 7:03 PDT",
                                      "2017-08-25 9:04 PDT" ))

I'm not sure how to best approach this problem.

user3357059
  • 1,122
  • 1
  • 15
  • 30
  • 4
    Help me out: Map `c(615,735,615 )` to `c("2017-08-25 10:15", "2017-08-25 12:15", "2017-08-25 10:15" )` please. I get the addition of `2017-08-25`. – Shawn Mehan Aug 25 '17 at 19:20
  • The Excel data has those values, but I need to convert them to times in R. I was dividing those numbers by 60 to get the 'minutes' but I needed to convert that a field in POSIXct class in R. – user3357059 Aug 28 '17 at 21:41

1 Answers1

3

Not sure what the values are but in case these are seconds you can use:

> dfOrig$StandarTime <- ISOdate(2017, 8, 25, hour = 0) + dfOrig$StandarTime
> dfOrig$AchievedTime <- ISOdate(2017, 8, 25, hour = 0) + dfOrig$AchievedTime
> dfOrig
          StandarTime        AchievedTime
1 2017-08-25 00:10:15 2017-08-25 00:13:14
2 2017-08-25 00:12:15 2017-08-25 00:07:03
3 2017-08-25 00:10:15 2017-08-25 00:09:04

ISOdate(2017, 8, 25, hour = 0) sets the start time, then you can add a value in seconds. You can also specify a time zone using tz = ""

JBGruber
  • 11,727
  • 1
  • 23
  • 45