[R] help on date dataset

anoumou teko_maurice at yahoo.fr
Sat Nov 10 14:21:50 CET 2012


Hi everybody, 
I am beginer in R and I need your precious help.
I want to create a small function  in R as in sas to retrieve date.
I have a file with data that import in R.
 DATE                       PAYS         nb_pays.ILI.
1   24/04/2009                 usa            0
2   24/04/2009                 usa            0
3   24/04/2009             Mexique            0
4   24/04/2009             Mexique            0
5   26/04/2009                 usa           20
6   26/04/2009                 usa           20
7   26/04/2009                 usa           20
8   26/04/2009                 usa           20
9   26/04/2009                 usa           20
10  26/04/2009             Mexique           18
11  27/04/2009                 usa           40
12  27/04/2009             Mexique           26
13  27/04/2009              Canada            6
14  27/04/2009               Spain            1
15  28/04/2009             Canada             6

I want to create something like that:
•	When entering two dates date1,date2 in the fuction extraction.
The result must be: a  new subdata  with one line  per date , per PAYS,per 
nb_pays.ILI (by summing all the number in variable nb_pays.ILI per date,per
country)  and the date must be between date1 and date2.
I sart to do somethings like that
extraction=function(date1,date2)
  {date<-derdata[["DATE"]]
   date
   sort(date)
   PAYS<-derdata[["PAYS"]]
   nb_pays.ILI<-derdata[["nb_pays.ILI."]]
   test1<-as.character(date,"%d %m %y")
   test1
   #the first date
   date1<- "04 03 2009"
   date1 <- strptime(date1, "%d %m %Y")
   date1
   unlist(unclass(date1))
   date1 <- as.POSIXct(date1)
   date1
   attributes(date1)
   date1 <-unclass(date1)
   date1
   
   #the second date
   date2<- "04 12 2009"
   date2 <- strptime(date2, "%d %m %Y")
   date2
   unlist(unclass(date2))
   date2 <- as.POSIXct(date2)
   date2
   attributes(date2)
   date2 <-unclass(date2)
   date2
   B1<- as.POSIXct(test1)
   B1 <-unclass(B1)
   B1
   B4 <- B1[(B1>date1) & (B1<date2)]
   B4
  
}




--
View this message in context: http://r.789695.n4.nabble.com/help-on-date-dataset-tp4649175.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list