3

Gmailから取得された日付と、そのためにPDT(America / Los_Angeles)またはPST(同じタイムゾーンの夏時間)で示されている日付の間の時間の長さを計算しようとしています。残りのデータは中央ヨーロッパ時間(ヨーロッパ/チューリッヒ)にあるため、PDTとPSTの日付をCET(CEST)に変換したいと思います。

次のコマンドを使用して、日付を適切なtzに変換しました。

DF$sendback_date1[!is.na(DF$sendback_date1)] <-
    force_tz(DF$sendback_date1[!is.na(DF$sendback_date1)],
             tz = "Europe/Zurich")

ここで問題が発生します。私のMacでは、force_tzコマンドによって次のエラーメッセージが生成されます。

Fehler in as.POSIXlt.character(time) :    character string is not in a
standard unambiguous format

このコマンドがLinuxで機能するのを見ました。私は何かが足りないのですか?Macはタイムゾーンに他の名前を使用しますか?

ご協力いただきありがとうございます!!

私の問題をより明確にするために、再現可能な例をここに投稿します。

library(lubridate)
    DF <- structure(list(sendback_date1 = c("12.05.31 11:12", "12.07.03 11:33", "12.04.24 09:59", "12.07.02 18:37", "12.07.02 20:02", "", "12.04.24 15:00", "", "12.03.02 13:37", "12.03.26 10:23", "", "12.04.24 09:20", "", "12.03.26 14:14", "12.03.02 10:20", "12.04.23 17:30", "12.05.30 11:03", "", "12.05.24 08:51", "12.03.30 10:02", "12.03.19 12:44"), sendback_date2 = c("", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""), send_date = c("12/05/22 01/17/10", "12/05/22 01/17/14", "12/04/23 07/27/29", "12/03/01 12/08/28", "12/03/23 07/46/59", "12/03/23 07/47/00", "12/04/23 07/27/30", "12/05/22 01/17/17", "12/03/01 12/08/30", "12/04/23 19/17/00", "12/03/01 21/29/00", "12/03/23 16/18/00", "12/05/22 10/00/00", "12/03/23 07/47/01", "12/03/01 12/08/32", "12/04/23 07/27/32", "12/05/22 01/17/20", "12/04/23 07/27/35", "12/05/22 01/17/21", "12/03/23 07/47/03", "12/03/01 12/08/34"), Daylight = c("PDT", "PDT", "PDT", "PST", "PDT", "PDT", "PDT", "PDT", "PST", "", "", "", "", "PDT", "PST", "PDT", "PDT", "PDT", "PDT", "PDT", "PST")), .Names = c("sendback_date1", "sendback_date2", "send_date", "Daylight"), row.names = 60:80, class = "data.frame")



DF[DF == ""] <- NA
    DF$send_date <- gsub("^\\s+|\\s+$", "", DF$send_date) 
DF


DF$sendback_date1[!is.na(DF$sendback_date1)] <- ymd_hm(DF$sendback_date1[!is.na(DF$sendback_date1)], tz = "Europe/Zurich")
DF$sendback_date2[!is.na(DF$sendback_date2)] <- ymd_hm(DF$sendback_date2[!is.na(DF$sendback_date2)], tz = "Europe/Zurich")

DF$send_date[!is.na(DF$send_date) & !is.na(DF$Daylight)] <- ymd_hms(DF$send_date[!is.na(DF$send_date) & !is.na(DF$Daylight)], tz = "America/Los_Angeles")
DF$send_date[!is.na(DF$send_date) & !is.na(DF$Daylight)] <- with_tz(DF$send_date[!is.na(DF$send_date) & !is.na(DF$Daylight)], tz = "Europe/Zurich")

DF$send_date[!is.na(DF$send_date) & is.na(DF$Daylight)] <- ymd_hms(DF$send_date[!is.na(DF$send_date) & is.na(DF$Daylight)], tz = "Europe/Zurich")

   dput(head(DF)) structure(list(sendback_date1 = c("12.05.22 13:57", "12.04.24 09:17",  
   "12.04.10 13:26", "12.03.09 10:09", "12.03.02 12:39", "12.05.22 12:33" ), 
   sendback_date2 = c("12.05.31 11:55", NA,  NA, NA, NA, NA), 
     sendback_date3 = c(NA_character_, NA_character_, NA_character_, 
     NA_character_, NA_character_, NA_character_), send_date = c("12/05/22 01/16/28", 
     "12/04/23 07/26/52", "12/03/23 07/46/30", "12/03/01 12/07/59", 
     "12/03/01 12/08/00", "12/05/22 01/16/32"), Daylight = c("PDT", 
     "PDT", "PDT", "PST", "PST", "PDT")), .Names = c("sendback_date1",  "sendback_date2", 
     "sendback_date3", "send_date",  "Daylight"), row.names = c(NA,  6L), class = "data.frame")


> str(DF)
'data.frame':   1004 obs. of  5 variables:
 $ sendback_date1: chr  "12.05.22 13:57" "12.04.24 09:17" "12.04.10 13:26" "12.03.09 10:09" ...
 $ sendback_date2: chr  "12.05.31 11:55" NA NA NA ...
 $ sendback_date3: chr  NA NA NA NA ...
 $ send_date     : chr  "12/05/22 01/16/28" "12/04/23 07/26/52" "12/03/23 07/46/30" "12/03/01 12/07/59" ...
 $ Daylight      : chr  "PDT" "PDT" "PDT" "PST" ...
4

0 に答える 0