Skip to content
Prev 154934 / 398506 Next

(no subject)

On 3 September 2008 at 20:00, Dr Eberhard W Lisse wrote:
| Hi,
| 
| I am getting accumulated data from PostgreSQL, ie for every day in
| which a condition is true I get the number (count) of cases. Starting
| date is 2008-01-01 and end day the last day for which the condition
| is true (which is not necessarily today).
| 
| I obviously do not get records (dates) with count = 0, in other words
| this is not a complete list of every day since 2008-01-01.
| 
| Now I want I plot this, with the sum on the Y axis and the months
| on the X axis, preferably as a line drawing.
| 
| Any ideas?

Sure. It's straightforward if you convert your date data to actual Date
types. 

So for argument's sake:
x y
1 2008-01-01 4
2 2008-01-21 6
3 2008-02-15 8
4 2008-03-08 5
5 2008-04-20 7
6 2008-05-10 2
7 2008-06-20 1
The key is the as.Date(). If your date characters have a different format,
specify it there.  See help(as.Date).

If you want to aggregates, slice, dice, summarise by time-unit (like months
or weeks), make this a zoo object and study the three excellent vignettes in
the zoo package.  R is pretty good at calculating on dates and times provided
it is given the data in the right form.

Hth, Dirk