他の時系列データをマージするために使用する時系列データフレームを作成します。POSIX DateTimeでタイムゾーンを維持する方法と、Rで強制的に導入されるNAsを回避する方法は?
私は上記のコードを実行する場合は、 'dates2010' と 'dates2011は' GMT形式であるdates2010 <- seq(as.POSIXct("2010-06-15 00:00:00", tz = "GMT"), as.POSIXct("2010-09-15 23:00:00", tz = "GMT"), by="hour") # make string of DateTimes for summer 2010
dates2011 <- seq(as.POSIXct("2011-06-15 00:00:00", tz = "GMT"), as.POSIXct("2011-09-15 23:00:00", tz = "GMT"), by="hour") # make string of DateTimes for summer 2011
dates <- c(dates2010, dates2011) # combine the dates from both years
sites <- c("a", "b", "c") # make string of all sites
datereps <- rep(dates, length(sites)) # repeat the date string the same number of times as there are sites
sitereps <- rep(sites, each = length(dates)) # repeat each site in the string the same number of times as there are dates
n <- data.frame(DateTime = datereps, SiteName = sitereps) # merge two strings with all dates and all sites
n <- n[order(n$SiteName, n$Date),] # re-order based on site, then date
:dates2010[1]
"2011-06-15 00:00:00 GMT"。 しかし、私は、オブジェクトを作成するESTに何らかの理由でフォーマットスイッチの「さかのぼり」:dates[1]
「2010年6月14日午後7時00分00秒EST」
多分それはPOSIXクラスとは何かを持っていますか?
class(dates2010)
[1] "POSIXct" "POSIXt"
私は問題を切り替え時間帯を避けるためにGMTにchange the default time zone for Rにしようとしました。これは、データフレーム「n」を注文し、他のデータフレームを「n」にマージしようとすると、NAコーションエラーが発生します。
n <- n[order(n$SiteName, n$Date),]
Warning message:
In xtfrm.POSIXct(x) : NAs introduced by coercion
どのようにタイムゾーンを一定に保ち、NA強制エラーを回避するかについての考えはありますか?ありがとうございました!
'DateTimeClasses':?「POSIXlt」オブジェクトの_Using 'C'は、現在のタイムゾーンに変換し、そして「POSIXct」オブジェクト上の任意の「TZONE」をドロップし、それらがすべて同じでマークされている場合でも、(属性_明らかにそれを避ける方法はないので、以下のように事実の後に属性をリセットするだけです。 – alistaire
あなたのメソッドは@Rich Scrivenを使って、 'dates'タイムゾーンを「GMT」に変更しました。 'dates < - 構造体(c(dates2010、dates2011)、tzone =" GMT ")'です。ありがとう。 – notacodr
ああ。その情報をありがとうございます@alistaire。 – notacodr