[R] calculate within-day correlations

emorway emorway at usgs.gov
Sat Sep 15 01:14:43 CEST 2012


Hi Joshua, 

I was attempting to work with your code on the larger datasets, which I have
to read in with 'read.table', but I've apparently missed something.   When I
attempt to massage the data.frame a bit in the code below, as.POSIXct drops
the time component which then precludes use of xts.  I think you'll see what
I mean (the rdb file is a text file containing the data, which is attached
to the post):

library(xts)
Q_hourly<-read.table("C:/temp/07130500_BelowJM_q.rdb",skip=59,col.names=c('date','time','tz','Q','rating','unknown'),colClasses=c("character","character","character","numeric","character","character"))

notice that

Q_hourly[1,]
#      date   time  tz   Q rating unknown
#1 19981001 000000 MDT 326      3       A
Q_hourly[2,]
 #     date   time  tz   Q rating unknown
#2 19981001 001500 MDT 326      3       A

and

paste(strptime(Q_hourly[1,1],"%Y%m%d"),"
",format(strptime(Q_hourly[1,2],"%H%M%S"),format="%H:%M:%S"),sep='')

#[1] "1998-10-01 00:00:00"

but for some reason, the time stamp is dropped in the following, which
breaks the call to xts (I think)

as.POSIXct(paste(strptime(Q_hourly[1,1],"%Y%m%d"),"
",format(strptime(Q_hourly[1,2],"%H%M%S"),format="%H:%M:%S"),sep=''),format="%Y-%m-%d
%H:%M:%S",tz="")

#[1] "1998-10-01 PDT"

The Q_use data.frame I'm building here should come out exactly 
http://r.789695.n4.nabble.com/file/n4643206/07130500_BelowJM_q.rdb
07130500_BelowJM_q.rdb the same as in my original post (above), but I can't
seem to seem to force the preservation of the time stamp even though I've
explicitly stated the format I want to be stored (...format="%Y-%m-%d
%H:%M:%S").  Any ideas?

xQ <- xts(Q_use["Q"], Q_use$date)
#Error in `[.data.frame`(x, indx) : undefined columns selected




--
View this message in context: http://r.789695.n4.nabble.com/calculate-within-day-correlations-tp4643091p4643206.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list