r - Adding hours to DateTime values from different time zones -


I have many informational posts related to POSIXct and other time functions in R. Time is struggling with time conversion with fields.

My time is stored as a number from an Excel file, in GMT, and included below.

  data & lt; - Structure (list (DATETIME = c (40,361.584526, 40,361.667836, 40,361.751285, 40,361.834421, 40,361.9 17 9 86, 40,362,000 9 72, 40,362.08447 9 , 40, 362.1673, 9, 40, 362, 25, 22, 40, 362.335301, 40, 362.417211, 40, 362.500 926, 40, 362.585185, 40, 362.6687, 96, 40, 362.751655, 40 , 362.834664, 40,362.9 17847, 40,363.001007, 40,363.084641, 40363.1675, 40363.334803, 40363.417616, 40363.502095, 40363.584514, 40363.7650625, 40363.834225, 40363.917743, 40354.335405, 40737.501782, 40603.917292, 40604.000556 , 40604.083808, 40604.167292, 40604.250579, 40,6 04.33375, 40604.417164, 40604.500625, 40604.584074, 40604.666 9 68, 40604.750613, 40,604.834306, 40604.91 7211, 40,605,000625, 40 , 605.083 9 58, 40605.167245, 40605.250567, 40605.333 9 24, 40,605.417488, 40,605.5006,94, 40,605.584306, 40,605.66728, 40,605 .750718, 40,605.834236, 40605.9 17 9 05, 4060665625, 40606.083 9 01, 40606.1672 92, 40606.25050 9, 41,271.500544, 40,048.9 17037 , 40049, 40,04 9,085 926, 40,049.958370 4, 40,049.966667, 40,049.97463, 40,049.8832593, 40051.666667, 40051.752593, 40051.835556, 40051.918519, 40052.001482, 40052.167407, 40,052.25037, 40,052.333333, 40,052.4162 9 6, 40,052.751111, 40,052.834074, 40,052.9 17037, 40053, 40,053.082 9 63, 40,053.16888 9, 40,053.251852, 40,053.334815, 40,053.417778, 40,053.500741, 40,053.583704, 40,053.666667, 40,054.084444), StudyArea = Structure (c (1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L) , 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L , 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L , 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3 L, 3L, 3L) .Lale = C ("cali", "colo", "pota"), class = "factor"). Name = c ("DateTime", "Striaria"), line.Name = C (NA, -90L), class = "data.frame")  

The head is here:

  & gt; Head (Data) Date Time StudyArea 1 40,361.58 Cali 2 40,361.67 Cali 3 40,361.75 Cali 4 40,361.83 Cali 5 40,361.92 Cali 6 40,362.00 Cali POSIXct change the date time to the first time a   
Use of code in GMT object

  Data $ TimeGMT & lt; - as.POSIXct (data $ date time * (60 * 60 * 24), original = "1899-12-30", tz = "GMT")  

My goal is that the TimeGMT Cutting from Kaili, Colo, and Patta is 8, 7 and 4 hours respectively. Below the code of my work, but clearly results in the wrong local dates

LocalDateTime
; -. As.POSIXct (ifelse (Data $ StudyArea == "Cali", Data $ TimeGMT - 8 * 60 * 60, Eiffel (Data $ Studyia == "Colo", Data $ TimeGMT - 7 * 60 * 60, Data $ TimeGMT - 4 * 60 * 60), original = "1899-12-30" I suspect that there is an easy way to do this and appreciate any help with coding. Where can I find a list of R Timezone formats, because I'm unable to locate someone on the  timezone ( help file. 

do this work

  • ", Data $ TimeGMT - 7 * 60 * 60, Data $ TimeGMT - 4 * 60 * 60), Original =" 1970-01-01 ", tz =" GMT ")

      head (cbind (data, local time), date time study time, timegmt local time, time 1 40361.58 cali 2010-07-02 14:01:43 2010-07-02 06:01:43 2 40361.67 Cali 2010-07-02 16:01:41 2010-07-02 08:01:41 3 40361.75 Cali 2010-07-02 18:01:51 2010-07-02 10:01:51 4 40361.83 Cali 2010 - 07-02 20:01:33 2010-07-02 12:01:33 540361.92 Cali 2010-07-02 22:01:53 2010-07-02 14:01:53 640362.00 Cali 2010-07-03 00: 01: 23 2010-07-02 16:01:23  

    will be an easy way

      local date time & lt; - Data $ TIMEGMT - ifelse (data $ studia == "cali", 8 * 60 * 60, iffell (data $ study arrowa == "colo", 7 * 60 * 60, 4 * 60 * 60))  

    In this way you do not have to worry about the conversion because ifelse () is not leaving the class


  • Comments

    Popular posts from this blog

    sqlite3 - UPDATE a table from the SELECT of another one -

    c# - Showing a SelectedItem's Property -

    javascript - Render HTML after each iteration in loop -