[R] subset daily to monthly in a zoo or xts

Enrico Schumann enricoschumann at yahoo.de
Mon Apr 23 12:09:15 CEST 2012


Hi Vikram,

maybe something like this?

require("zoo")

## a daily zoo series
z <- zoo(1:200, as.Date("2012-01-01") + 1:200)

## add some NAs
z[ceiling(runif(10)*200)] <- NA

## aggregate to monthly
aggregate(z, format(index(z), "%Y-%m"), length)
aggregate(z, format(index(z), "%Y-%m"), function(x) sum(is.na(x)))
aggregate(z, format(index(z), "%Y-%m"), function(x) sum(is.na(x))/length(x))



Regards,
Enrico

Am 23.04.2012 11:27, schrieb Vikram Bahure:
> Dear R users,
>
> I want to subset a daily zoo series according to its month, find % of
> "NA" in each month.
>
> I am finding it difficult to subset the daily dataset into monthly
> for the given operation.I am planning to do this for a huge dataset.
>
> Thanks in advance.
>
> Regards Vikram
>
>

-- 
Enrico Schumann
Lucerne, Switzerland
http://nmof.net



More information about the R-help mailing list