[R] POSIXct and chron issues with tz

Sherri Heck sheck at ucar.edu
Sun Jan 4 01:57:31 CET 2009


 Dear All-

I am trying to merge two data files - they have different date formats 
and different times zones.  I need to match up the date/time of the 
datasets and then invoke a conditional statement, such as: if dataC$mph 
is >= 12 then keep dataM$co23 for the corresponding time/date stamp.

snippets of data files:

*dataC.txt*
 LST   in     mph    Deg   DegF  DegF2    %    volts   Deg    mph2   w/m2
0506010000   0.00   13.6  218.1   36.8   -999   65.1   -999   -999   
18.2    0.2
0506010005   0.00   12.9  214.3   36.8   -999   65.5   -999   -999   
16.9    0.2
0506010010   0.00   14.4  215.7   36.9   -999   65.4   -999   -999   
20.4    0.2

*dataM.txt*
doy yr mon day hr hgt1 hgt2 hgt3 co21 co22 co23 sig1 sig2 sig3 dif flag

244.02083 2005 09 01 00 2.5 5.8 9.1 -999.99 -999.99 -999.99 -999.99 
-999.99 -999.99 -999.99 PRE
244.0625 2005 09 01 01 2.5 5.8 9.1 -999.99 -999.99 -999.99 -999.99 
-999.99 -999.99 -999.99 PRE
244.10417 2005 09 01 02 2.5 5.8 9.1 -999.99 -999.99 -999.99 -999.99 
-999.99 -999.99 -999.99 PRE

*Code:*

z <- read.zoo("dataC.txt", header = TRUE, na.strings = -999,      
        format = "%y%m%d%H%M", FUN = 
as.chron,                                                                
        colClasses = c("character", rep("numeric", 10)))

DF <- read.table("C:/R/dataM.txt", header = TRUE, na.strings = -999.99)
tt <- with(DF, chron(paste(mon, day, yr, sep = "/"),
       paste(hr, 0, 0, sep = ":")))
       timeconv <-  as.POSIXct(tt, tz="")
       z2 <- zoo(data.matrix(DF), timeconv)


*example of output of data files*

 >z[1,]
                    in.  mph   Deg DegF DegF2   X. volts Deg.1 mph2 w.m2
(06/01/05 00:00:00)   0 13.6 218.1 36.8    NA 65.1    NA    NA 18.2  0.2


 > z2[1,]
                         doy   yr mon day hr hgt1 hgt2 hgt3 co21 co22 
co23 sig1 sig2 sig3 dif flag
2005-08-31 18:00:00 244.0208 2005   9   1  0  2.5  5.8  9.1   NA   NA   
NA   NA   NA   NA  NA    1

*#merging data files z, z2*
m <- merge(z, z2, all = c(FALSE, TRUE))
m[m==-999.99]<-NA
m2 <- m[m$mon %in% c(6,7,8),]

*returns the following warning message:*
Warning message:
In merge.zoo(z, z2, all = c(FALSE, TRUE)) :
  Index vectors are of different classes: chron POSIXt

I cannot find a way to deal with the timezone in chron.  But, I found 
through the help pages that POSIXct deals with tz.  However, it doesn't 
seem these two different formats are compatible to merge.  Any thoughts 
would be appreciated.

cheers,

sherri




More information about the R-help mailing list