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
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Sun 03 Apr 2011 - 03:09:59 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 03 Apr 2011 - 03:40:26 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive