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 [[alternative HTML version deleted]]
On Mon, 23 Apr 2012, Vikram Bahure wrote:> 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.Use aggregate(z, as.yearmon, ...) for aggregation to a monthly series. A simple artificial example is: ## data with NAs set.seed(1) x <- rnorm(50) x[sample(1:50, 10)] <- NA ## as zoo z <- zoo(x, as.Date("2012-01-01") + 0:49) ## proportion of NAs aggregate(z, as.yearmon, function(x) mean(is.na(x))) hth, Z> Thanks in advance. > > Regards > Vikram > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
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
Reasonably Related Threads
- How to do operations on zoo/xts objects with Monthly and Daily periodicities
- Using zoo() to aggregate daily data to monthly means
- confused with yearmon, xts and maybe zoo
- Time series: xts/zoo object at annual (yearly) frequency
- converting a zoo or an xts to a data frame