[R] How to plot a histogram of weekday frequencies in a list of dates?

Wu Gong wg2f at mtmail.mtsu.edu
Fri Jul 16 05:42:15 CEST 2010


Hope it works.

## Create a sample of dates 
dates <- sample(seq(ISOdate(2009,1,1), ISOdate(2009,12,31), "hour"),1000)

## Create 14 labels for barplot("Mon AM","Mon PM",etc.)
labels <- format(seq(ISOdate(2010,7,11,5), ISOdate(2010,7,18,4), "12
hours"),"%a %p")

## Use table function to calculate the frequency of each time intervel
## Use format "%w %p" to get the weekday name and AM/PM indicator of the
dates
## Minus 12*60*60 seconds to change AM interval from 0-12AM to 7AM-7PM
barplot(table(format((dates-12*60*60), "%w %p")),names.arg=labels)


-----
A R learner.
-- 
View this message in context: http://r.789695.n4.nabble.com/How-to-plot-a-histogram-of-weekday-frequencies-in-a-list-of-dates-tp2290601p2290917.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list