I have a dataset with transactions and a timestamp at which they occoured during a day. The time stamp is in the format YYYY/MM/DD hh:mm:ss. I would like to plot a timeseries of the transactions to see if there is a particular time in the day when there is a spike in transactions. Ofcourse the YYYY/MM/DD can be dropped since I am monitoring activity for the day and the actual date is unimportant. Can anyone give me some direction on this. I could possibly build a frequency table but not sure how to plot against the timestamp in the format above. Any help would be appreciated. -Dhiren
On 8/17/05, Dhiren DSouza <dhiren22 at hotmail.com> wrote:> I have a dataset with transactions and a timestamp at which they occoured > during a day. The time stamp is in the format YYYY/MM/DD hh:mm:ss. I would > like to plot a timeseries of the transactions to see if there is a > particular time in the day when there is a spike in transactions. Ofcourse > the YYYY/MM/DD can be dropped since I am monitoring activity for the day and > the actual date is unimportant. > > Can anyone give me some direction on this. I could possibly build a > frequency table but not sure how to plot against the timestamp in the format > above. Any help would be appreciated.Lets say your times are in a character vector tt. (If the dates are there too use substring to remove them.) Then convert them to times class (of library chron) which will represent them internally as a fraction of a day where the day starts at 0 and goes to 1 so that 0.5 is noon. Since we want a more meaningful axis do not use the automatic plot axis (xaxt = "n") and also restrict the xaxis to the internval 0:1. So that we can get all the hours to fix reduce the size of the axis labels to 70%. Then redraw it yourself with the hours labelled and add some light grey vertical lines if you like. library(chron) tt <- c("10:11:12", "09:10:11", "01:02:03") tt.times <- times(tt) plot(density(tt.times), xaxt = "n", xlim = 0:1, xlab = "Hour") axis(1, 0:24/24, 0:24, cex.axis = 0.7) abline(v = 0:24/24, col = "lightgrey") See RNews 4/1 Help Desk article for more.
Have you considered the "zoo" package? It has a "vignette" that I found very useful. After 'install.packages("zoo")', try the following: Zoo <- vignette("zoo") print(Zoo) # to open the narrative vignette in an Adobe Acrobat reader edit(Zoo) # to open a script file in RGui to make it easy for you # to process the R commands line by line, edit them as you wish, etc. # If you use XEmacs, do NOT use "edit(Zoo)". Instead do the following: Stangle(Zoo$file) # This will write the R commands to a file, which you can then open # and process line by line as in RGui. spencer graves Dhiren DSouza wrote:> I have a dataset with transactions and a timestamp at which they occoured > during a day. The time stamp is in the format YYYY/MM/DD hh:mm:ss. I would > like to plot a timeseries of the transactions to see if there is a > particular time in the day when there is a spike in transactions. Ofcourse > the YYYY/MM/DD can be dropped since I am monitoring activity for the day and > the actual date is unimportant. > > Can anyone give me some direction on this. I could possibly build a > frequency table but not sure how to plot against the timestamp in the format > above. Any help would be appreciated. > > -Dhiren > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html-- Spencer Graves, PhD Senior Development Engineer PDF Solutions, Inc. 333 West San Carlos Street Suite 700 San Jose, CA 95110, USA spencer.graves at pdf.com www.pdf.com <http://www.pdf.com> Tel: 408-938-4420 Fax: 408-280-7915