Sorry - never mind. It turns out I did not load the zoo package. That
was the reason.
On Wed, Apr 6, 2011 at 12:14 PM, Dimitri Liakhovitski
wrote:
> Guys, sorry to bother you again:
>
> I am running everything as before (see code below - before the line
> with a lot of ##). But now I am getti
Guys, sorry to bother you again:
I am running everything as before (see code below - before the line
with a lot of ##). But now I am getting an error:
Error in eval(expr, envir, enclos) : could not find function "na.locf"
I also noticed that after I run the 3rd line from the bottom: "wk <-
as.
On Wed, Mar 30, 2011 at 5:10 PM, Dimitri Liakhovitski
wrote:
> Yes, zoo! That's what I forgot. It's great.
> Henrique, thanks a lot! One question:
>
> if the data are as I originally posted - then week numbered 52 is
> actually the very first week (it straddles 2008-2009).
> What if the data much
On Mar 30, 2011, at 2:35 PM, Dimitri Liakhovitski wrote:
Henrique, this is great, thank you!
It's almost what I was looking for! Only one small thing - it doesn't
"merge" the results for weeks that "straddle" 2 years. In my example -
last week of year 2008 and the very first week of 2009 are o
This puts 'NA' in the first week of the year.
Take a look on the code below:
2009.52 %% 1
On Wed, Mar 30, 2011 at 6:35 PM, Dimitri Liakhovitski
wrote:
> Henrique, this is beautiful, thank you so much.
> This is a great and correct solution.
>
> A stupid question: what does the line is.na(wk) <
Henrique, this is beautiful, thank you so much.
This is a great and correct solution.
A stupid question: what does the line is.na(wk) <- wk %% 1 == 0 do?
Thank you!
Dimitri
On Wed, Mar 30, 2011 at 5:25 PM, Henrique Dallazuanna wrote:
> You're right:
>
> wk <- as.numeric(format(myframe$dates, "%Y
You're right:
wk <- as.numeric(format(myframe$dates, "%Y.%W"))
is.na(wk) <- wk %% 1 == 0
solution<-aggregate(value ~ group + na.locf(wk), myframe, FUN = sum)
On Wed, Mar 30, 2011 at 6:10 PM, Dimitri Liakhovitski
wrote:
> Yes, zoo! That's what I forgot. It's great.
> Henrique, thanks a lot! One
Yes, zoo! That's what I forgot. It's great.
Henrique, thanks a lot! One question:
if the data are as I originally posted - then week numbered 52 is
actually the very first week (it straddles 2008-2009).
What if the data much longer (like in the code below - same as before,
but more dates) so that
Try this:
library(zoo)
wk <- as.numeric(format(myframe$dates, '%W'))
is.na(wk) <- wk == 0
aggregate(value ~ group + na.locf(wk), myframe, FUN = sum)
On Wed, Mar 30, 2011 at 4:35 PM, Dimitri Liakhovitski
wrote:
> Henrique, this is great, thank you!
>
> It's almost what I was looking for! Only o
Here is a way of taking a sequence of dates and breaking them into
weeks that start on Monday (you can change it) and it will span across
years:
> # create a couple of years of dates
> x <- seq(as.Date('2009-7-8'), as.Date('2012-3-7'), by = '1 day')
> # determine when the Monday for the first date
Henrique, this is great, thank you!
It's almost what I was looking for! Only one small thing - it doesn't
"merge" the results for weeks that "straddle" 2 years. In my example -
last week of year 2008 and the very first week of 2009 are one week.
Any way to "join them"?
Asking because in reality I'
Try this:
aggregate(value ~ group + format(dates, "%Y.%W"), myframe, FUN = sum)
On Wed, Mar 30, 2011 at 11:23 AM, Dimitri Liakhovitski
wrote:
> Dear everybody,
>
> I have the following challenge. I have a data set with 2 subgroups,
> dates (days), and corresponding values (see example code belo
12 matches
Mail list logo