我有一个Spark(1.6.3)Dataframe列日期“created_at”和偏移“utc_offset”:

dt<-df$created_at
head(df)
                      created_at utc_offset
1 Sun Jul 31 22:25:01 +0000 2016       <NA>
2 Sun Jul 31 22:25:01 +0000 2016       <NA>
3 Fri Jun 03 10:16:57 +0000 2016     -25200
4 Mon May 30 19:23:55 +0000 2016     -18000

我想在日期中添加偏移量 . 我试试:

str <- strptime(dt, "%a %b %d   %H:%M:%S %z %Y", tz = "GMT")
dt.gmt <- as.POSIXct(str, tz = "GMT")
dt.gmt<-ifelse (is.na(df$utc_offset),dt.gmt, dt.gmt+df$utc_offset)
class(dt.gmt) <- c("POSIXct")
head(dt.gmt)

这使:

> dt.gmt<-ifelse (is.na(df$utc_offset),dt.gmt, dt.gmt+df$utc_offset)
Error in unclass(e1) + unclass(e2) : 
  non-numeric argument to binary operator
In addition: Warning message:
In is.na(df$utc_offset) :
  is.na() applied to non-(list or vector) of type 'S4'
> class(dt.gmt) <- c("POSIXct")
> head(dt.gmt)
[1] NA                        "2016-02-02 09:38:12 GMT" "2016-02-02 09:38:45 GMT" "2016-02-02 09:39:31 GMT" "2016-02-02 09:40:14 GMT" "2016-02-02 09:41:12 GMT"

我以为is.na会覆盖我 . 我想它可能是dt.gmt不是数字 . 有没有简单的方法来打印每列的非数字?但我确实得到输出,虽然它与输入没有任何对应关系(我想我的最早日期是2016年5月) .