# Re: [R] Discretizing data rows into regular intervals

From: Daniel Malter <daniel_at_umd.edu>
Date: Sat, 02 Apr 2011 22:06:51 -0500 (CDT)

Sorry, I did not get the question because I read it too sloppily. I hope this is not homework. You can proceed along this example:

set.seed(32345)

#Value of observation

value=rpois(60,100)

#Day of observation

day=sample(1:1080,50,replace=F)
day=sort(day)

#Assume 3 years
#Assume months have all 30 days
#For real dates, the breaks in cut()
#have to be defined properly

all.days=seq(from=1,to=1080)
quarter=cut(all.days,breaks=12)
quarter=as.factor(as.numeric(quarter))

#In which quarter is a certain observation
quarter.of.day=quarter[day]

#What's the minimum day in a quarter

min.day=tapply(day,quarter.of.day,min)

#What's the value at that day

values.at.min.day=value[which(day%in%min.day)]

hth,
daniel

```--
View this message in context: http://r.789695.n4.nabble.com/Discretizing-data-rows-into-regular-intervals-tp3422921p3422975.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help