[R] calculate weeks for 2005 and aggregate them

Marco Helbich marco.helbich at gmx.at
Tue Apr 7 14:32:31 CEST 2009


Dear list,

here is an example of my dataset:

date <- c("20-08-2005", "27-08-2005", "19-08-2005", "29-08-2005", 
"01-08-2005", "01-08-2005",
  "25-08-2005", "15-08-2005", "11-08-2005", "12-08-2005", "18-08-2005", 
"02-08-2005",
  "04-08-2005", "15-08-2005", "17-08-2005", "24-08-2005", "15-08-2005", 
"30-08-2005",
  "30-08-2005", "02-08-2005", "05-08-2005", "04-08-2005", "22-08-2005", 
"11-08-2005",
  "25-08-2005", "29-08-2005", "07-08-2005", "04-08-2005", "08-08-2005", 
"08-08-2005")
hcrime <- factor(c("Aggravated Assault", "Burglary", "Robbery"))
data <- cbind(date, hcrime)

I have following questions:
a) how can I find out the weeks of every date
b) aggregate the dates falling in the same week
c) sum up the different crimes per week

for better understanding here is an example for a) and b):
date                    week
27-08-2005            99
27-08-2005            99
29-08-2005            99

and here one for c):

week    crimes_Robbery    crimes_Robbery
98                2                            1
99                3                            0

thank you very much for your help!
best regards
Marco




More information about the R-help mailing list