[R] Questions about doing analysis based on time

APOCooter mikeedinger16 at gmail.com
Thu Jul 12 21:42:55 CEST 2012


Another new question:

I want to be able to subset the data based on whether or not that data point
was recorded on a holiday.  The is.holiday() function from the chron package
would be perfect for this.  However, when I try it, the following happens
(I'm also using the timeDate package):

> holidays<-ChristmasDay(2008:2011)
> holidays<-as.POSIXct(holidays, format="%Y-%m-%d")
> subset(OverallData, is.holiday(OverallData$Date))
[1] Date  Score
<0 rows> (or 0-length row.names)

I'm not sure what I'm supposed to do to make this work



"half.hours <- function(x){ 
        s <- strsplit(as.character(x), ":") 
        H <- as.integer(sapply(s, `[`, 1)) 
        M <- as.integer(sapply(s, `[`, 2)) 
        h <- (H*60 + M)/60 
        floor(h/0.5)*0.5 
} 
half.hours(dat$SunTime) "

When I did this, everything came out as NA.  But I used the following code
and it worked:

halfhours<-function(x){
	H<-hours(x)
	M<-minutes(x)
	ifelse(M<30, H, H+.5)
}

Thanks again for your help!

--
View this message in context: http://r.789695.n4.nabble.com/Questions-about-doing-analysis-based-on-time-tp4634230p4636353.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list