Message-ID: <34FC5EAD-1AD4-44AE-81CC-C028527A5FEE@comcast.net>
Date: 2009-11-29T13:31:36Z
From: David Winsemius
Subject: column of dates into time series
In-Reply-To: <8d4c23b10911290452t6f7cf47ufbaf90a440fd02a6@mail.gmail.com>
On Nov 29, 2009, at 7:52 AM, Linlin Yan wrote:
> There is no year() function. Maybe you can try format() instead.
>
> On Sun, Nov 29, 2009 at 8:44 PM, DispersionMap <frenchcr at btinternet.com
> > wrote:
>>
>> i have a column of dates in this format:
>>
>> data[,"Raised.Date"] <- as.Date(data[,"Raised.Date"], "%d/%m/%Y");
>> data[1:10,"Raised.Date"]
>> [1] "2006-07-07" "2006-07-07" "2006-04-03" "2006-04-03" "2006-04-03"
>> "2006-04-03" "2006-04-03" "2006-04-03" "2006-04-03" "2006-04-03"
>>
>> I can turn them into months like this...
>>
>> Month<-months(data[,"Raised.Date"])
>> Month[1:10]
>> [1] "July" "July" "April" "April" "April" "April" "April" "April"
>> "April"
>> "April"
>>
>>
>> But i also want to turn them into years (and also weeks later on),
>> so tried
>> this...
library(chron)
?cut.dates
The argument breaks has several options including one of c("days",
"weeks", "months", "year")
> dts <- Sys.Date() - 1:20
> cut(dts, breaks="weeks")
[1] 2009-11-23 2009-11-23 2009-11-23 2009-11-23 2009-11-23
2009-11-23 2009-11-16 2009-11-16 2009-11-16 2009-11-16
[11] 2009-11-16 2009-11-16 2009-11-16 2009-11-09 2009-11-09 2009-11-09
2009-11-09 2009-11-09 2009-11-09 2009-11-09
Levels: 2009-11-09 2009-11-16 2009-11-23
I was a bit puzzled when I tried cut.dates as the function which
throws a function not found error.
>>
>> Year<-year(data[,"Raised.Date"])
>> Error: could not find function "year"
>
David Winsemius, MD
Heritage Laboratories
West Hartford, CT