[R] Questions on Data reading using zoo package

Gabor Grothendieck ggrothendieck at gmail.com
Tue Feb 21 13:52:39 CET 2012


On Tue, Feb 21, 2012 at 2:25 AM, jpm miao <miaojpm at gmail.com> wrote:
> Hello,
>
>   I try to handle the data using read.csv , zoo and aggregate functions.
> The data contains NA values. After aggregating monthly data into quarterly
> data, all data become NA. Is it because I don't properly aggregate the data
>  in the presence of NAs?   What can I do?
>
>   Another problem is that the date in month is presented in Chinese (My OS
> is in Chinese.) How can I set the default language to English?
>
>   Thanks,
>
> Miao
>

mean has an na.rm = TRUE argument you can use.  See ?mean

library(zoo)
z <- zoo(c(1:4, NA), as.Date("2000-01-01") + c(0, 40, 50, 60, 70))
aggregate(z, as.yearmon, FUN = mean, na.rm = TRUE)

On my Windows system this R code sets dates and times to English:
Sys.setlocale("LC_TIME", "English")

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list