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> x1 <- read.csv(file="120210CPILEADdata.csv", header=TRUE)> x1TIME CPI CPIZF UNR UNRSA 1 1978M01 NA NA 2.01 2.16 2 1978M02 NA NA 1.84 1.84 3 1978M03 NA NA 1.76 1.91 4 1978M04 NA NA 1.58 1.86 5 1978M05 NA NA 1.70 1.81 6 1978M06 NA NA 1.65 1.69 7 1978M07 NA NA 1.84 1.66 8 1978M08 NA NA 1.88 1.52 9 1978M09 NA NA 1.89 1.64 10 1978M10 NA NA 1.53 1.48 11 1978M11 NA NA 1.12 1.13 12 1978M12 NA NA 1.20 1.30 13 1979M01 NA NA 1.29 1.48 14 1979M02 NA NA 1.30 1.26 15 1979M03 NA NA 1.19 1.36 16 1979M04 NA NA 1.09 1.38 17 1979M05 NA NA 1.18 1.33 18 1979M06 NA NA 1.13 1.20 19 1979M07 NA NA 1.54 1.38 20 1979M08 NA NA 1.54 1.19 21 1979M09 NA NA 1.41 1.17 22 1979M10 NA NA 1.17 1.08 23 1979M11 NA NA 1.20 1.19 24 1979M12 NA NA 1.23 1.32 25 1980M01 NA NA 0.95 1.02 26 1980M02 NA NA 1.10 1.18 27 1980M03 NA NA 1.06 1.20 28 1980M04 NA NA 0.93 1.24 29 1980M05 NA NA 1.19 1.38 30 1980M06 NA NA 1.30 1.36 31 1980M07 NA NA 1.52 1.35 32 1980M08 NA NA 1.62 1.26> x1zoo<-zoo(x1, as.yearmon(1978)+seq(0,nrow(x1)-1)/12, frequency=12)> x1zooTIME CPI CPIZF UNR UNRSA ¤@¤ë 1978 1978M01 <NA> <NA> 2.01 2.16 ¤G¤ë 1978 1978M02 <NA> <NA> 1.84 1.84 ¤T¤ë 1978 1978M03 <NA> <NA> 1.76 1.91 ¥|¤ë 1978 1978M04 <NA> <NA> 1.58 1.86 ¤¤ë 1978 1978M05 <NA> <NA> 1.70 1.81 ¤»¤ë 1978 1978M06 <NA> <NA> 1.65 1.69 ¤C¤ë 1978 1978M07 <NA> <NA> 1.84 1.66 ¤K¤ë 1978 1978M08 <NA> <NA> 1.88 1.52 ¤E¤ë 1978 1978M09 <NA> <NA> 1.89 1.64 ¤Q¤ë 1978 1978M10 <NA> <NA> 1.53 1.48 ¤Q¤@¤ë 1978 1978M11 <NA> <NA> 1.12 1.13 ¤Q¤G¤ë 1978 1978M12 <NA> <NA> 1.20 1.30 ¤@¤ë 1979 1979M01 <NA> <NA> 1.29 1.48 ¤G¤ë 1979 1979M02 <NA> <NA> 1.30 1.26 ¤T¤ë 1979 1979M03 <NA> <NA> 1.19 1.36 ¥|¤ë 1979 1979M04 <NA> <NA> 1.09 1.38 ¤¤ë 1979 1979M05 <NA> <NA> 1.18 1.33 ¤»¤ë 1979 1979M06 <NA> <NA> 1.13 1.20 ¤C¤ë 1979 1979M07 <NA> <NA> 1.54 1.38 ¤K¤ë 1979 1979M08 <NA> <NA> 1.54 1.19 ¤E¤ë 1979 1979M09 <NA> <NA> 1.41 1.17 ¤Q¤ë 1979 1979M10 <NA> <NA> 1.17 1.08 ¤Q¤@¤ë 1979 1979M11 <NA> <NA> 1.20 1.19 ¤Q¤G¤ë 1979 1979M12 <NA> <NA> 1.23 1.32 ¤@¤ë 1980 1980M01 <NA> <NA> 0.95 1.02 ¤G¤ë 1980 1980M02 <NA> <NA> 1.10 1.18 ¤T¤ë 1980 1980M03 <NA> <NA> 1.06 1.20 ¥|¤ë 1980 1980M04 <NA> <NA> 0.93 1.24 ¤¤ë 1980 1980M05 <NA> <NA> 1.19 1.38 ¤»¤ë 1980 1980M06 <NA> <NA> 1.30 1.36 ¤C¤ë 1980 1980M07 <NA> <NA> 1.52 1.35 ¤K¤ë 1980 1980M08 <NA> <NA> 1.62 1.26> x1zooq<-aggregate(x1zoo, as.yearqtr, FUN=mean)There were 50 or more warnings (use warnings() to see the first 50) > x1zooq TIME CPI CPIZF UNR UNRSA 1978 Q1 NA NA NA NA NA 1978 Q2 NA NA NA NA NA 1978 Q3 NA NA NA NA NA 1978 Q4 NA NA NA NA NA 1979 Q1 NA NA NA NA NA 1979 Q2 NA NA NA NA NA 1979 Q3 NA NA NA NA NA 1979 Q4 NA NA NA NA NA 1980 Q1 NA NA NA NA NA 1980 Q2 NA NA NA NA NA 1980 Q3 NA NA NA NA NA [[alternative HTML version deleted]]
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
Apparently Analagous Threads
- Questions on plotting using zoo toolbox: (1) dual axes (2)legend
- vorbis-dev´Ô ¾È³çÇϼ¼¿ä? *^^*((¿µ¾î & ÀϾî mailing service È«º¸))*^^*
- vorbis´Ô ¾È³çÇϼ¼¿ä? *^^*((¿µ¾î & ÀϾî mailing service È«º¸))*^^*
- How can I tabulate time series data (in RStudio or any other R editor)?
- 特价电脑配件、手提电脑、手机,货到付款