[R] Zoo object problem: problem when I attempt to create a zoo object of only one column

2012-08-09 Thread jpm miao
Hi, Part of my program is to calculate the number of time series in a zoo object. It works well if it has more than one time series, but it fails if it has only one. How can I access the number of column (i.e. the number of time series) when I have only one column? Why is the number of an objec

[R] How can I read time series data to create zoo objects if I have two title lines?

2012-08-03 Thread jpm miao
Hello, This is a standard example in which I read the time series data from a csv file and create a zoo object: x0 <- read.csv(file="CPI.csv", header=TRUE) time_0<-as.yearmon("1981-01")+(0:371)/12 x0zoo<-zoo(x0, time_0) The data look like this: TIME CPI CPI_food CPI_Clothes CPI_House

Re: [R] How can I declare an empty zoo object?

2012-07-31 Thread jpm miao
Even when indices (dates) of two zoo object don't match, I can cbind them. It works for me! Thanks, Miao 2012/7/31 R. Michael Weylandt > On Mon, Jul 30, 2012 at 11:18 PM, jpm miao wrote: > > Hi, > > > >I let xzoo be an empty object: > > >

[R] How can I declare an empty zoo object?

2012-07-30 Thread jpm miao
Hi, I let xzoo be an empty object: > xzoo<-{} and I have an existing zoo object x1zoo_f. I would like to combine the two to make a new zoo object, and continue doing so in a loop, which is not shown here. However, when I type > xzoo<-cbind(xzoo, x1zoo_f) An error message emerges

[R] How can I access an element of a string?

2012-07-26 Thread jpm miao
ect.org [mailto:r-help-boun...@r-project.org] > > On Behalf Of jpm miao > > Sent: Thursday, July 26, 2012 9:12 PM > > To: r-help > > Subject: [R] How can I access the title of a table read via read.csv? > > > > Hi, > > > >I have a table which I can read via

[R] How can I access the title of a table read via read.csv?

2012-07-26 Thread jpm miao
Hi, I have a table which I can read via read.csv: fx1<-read.csv(file="A_FX_M.csv", header=TRUE) TIME REERNTDJPY GBPHKD 1 198001 124.26 36.030 237.96 2.263980 4.8366 2 198002 126.59 36.030 244.05 2.290426 4.8765 3 198003 128.33 36.026 248.62 2.206045 4.9960 4 198004 127.

Re: [R] How can I correctly access a string element of a dataframe?

2012-07-26 Thread jpm miao
hey are read in thru stringsAsFactors=FALSE or > > otherwise as explained therein -- or convert them with as.character() > > when you access them, e.g. > > x1<-read.csv(file=as.character(m2q[1,2])) > > -- Bert > > > > > On Thu, Jul 26, 2012 at 7:53 AM,

[R] How can I correctly access a string element of a dataframe?

2012-07-26 Thread jpm miao
Dear All, I would like to read the data file via read.csv (the 3rd line of the following program) and the file name is stored in a dataframe. Since I have several files to read, I store the file names as well as the sample period inside a file “B_M2Q.csv” and I read the file name first, and th

[R] zoo package; a question on as.yearmon and as.yearqtr

2012-05-03 Thread jpm miao
Hello, In zoo package, if I would like the time frame to be 1981M01 to 1982M12, then I code time_0<-as.yearmon("1981-01")+(0:23)/12 However, if the time frame of interest becomes 1981M01 to 2011M12, it is relatively hard to calculate the number of months. Is there any faster way to do it?

[R] How can I read the "text" or "character string" from a txt file?

2012-05-01 Thread jpm miao
Hello, I have a large number of time series, which needs to be transformed by log or difference. Some of them are just processed by "level" (LV) without any transformation. For that purpose, I produce a text file (.csv or .xls) as follows: DLN DLNDLN LV LV LV... How can I read the

[R] Why does my R compiler repeat my program whenever it is compiled?

2012-04-30 Thread jpm miao
Hi, I am using RStudio as my R editor. After someday I accidentally hit something, the whole program is repeated in the Console whenever I compile it. How can I fix it so that the whole program won't be repeated in the future? Thanks, miao [[alternative HTML version deleted]]

[R] Could dynlm function work for xts objects?

2012-04-11 Thread jpm miao
It seems to only works for zoo or ts objects? I tried to run it for xts objects, and error message occurs. Once I coerce it to be an zoo object (by as.zoo), it works. Error message: Error in model.frame.default(formula = dynformula(PIh - PI ~ L(X, 0:i) + : variable lengths differ (found for

Re: [R] Definition of "lag" is opposite in ts and xts objects!

2012-04-11 Thread jpm miao
BTW, zoo is like ts in the application of lag. In other words, zoo and xts are opposite in this issue. 2012/4/12 jpm miao > Example: > Will ts objects be obsolete or modified? > > > a[,1] > 1983 Q1 2.747365190 > 1983 Q2 2.791594762 > 1983 Q

[R] Definition of "lag" is opposite in ts and xts objects!

2012-04-11 Thread jpm miao
Example: Will ts objects be obsolete or modified? > a[,1] 1983 Q1 2.747365190 1983 Q2 2.791594762 1983 Q3 -0.009953715 1983 Q4 -0.015059485 1984 Q1 -1.190061246 1984 Q2 -0.553031799 1984 Q3 0.686874720 1984 Q4 0.953911035> lag(a,4)[,1] 1983 Q1 NA 1983

Re: [R] What is a better way to deal with lag/difference and loops in time series using R?

2012-04-11 Thread jpm miao
the time indices while keeping > all the data, [so the fourth data point is the same value -- just a > different time point] what you may want to do is cbind() the objects > to see how they line up now. > > cbind(PI1, lag(PI1,4)) > > Hope this helps, > Michael > > On Tue

[R] What is a better way to deal with lag/difference and loops in time series using R?

2012-04-10 Thread jpm miao
Hello, I am writing codes for time series computation but encountering some problems Given the quarterly data from 1983Q1 to 1984Q2 PI1<-ts(c(2.747365190,2.791594762, -0.009953715, -0.015059485, -1.190061246, -0.553031799, 0.686874720, 0.953911035), start=c(1983,1), frequency=4) > PI1

[R] Time series - year on year growth rate

2012-04-06 Thread jpm miao
Hello, Is there a function in R that calculates the year-on-year growth rate of some time series? In EView the function is @pchy. Thanks, miao [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.et

[R] Finding the maximum elements in an array/matrix

2012-03-29 Thread jpm miao
Hello, I would like to find the maximum element in a matrix or an array but it does not return what I want. For example, If I have a 2*2 matrix A whose maximum element is the A(1,2). I would like the answer (1,2), but it returns 3, which is the ordinal if one counts by columns. Is there any

[R] Questions on user defined function

2012-03-29 Thread jpm miao
Hello, I am new to the construction of user defined functions in R. I do see the syntax of the function in many R reference but don't see the structures / paths issue. Two basic questions: 1. Should the function embedded in the main program? Could a function be a separate R file (like Matlab)?

[R] Prediction using dynlm

2012-03-28 Thread jpm miao
Hello, I intend to perform FORECASTING with the "dynlm" package since I have a bunch of time series data, and my model is a little deviating from the standard AR. Therefore my first attempt is to perform AR forecasting based on dynlm package. First of all, I generate an ARIMA model and then

[R] Questions on plotting using zoo toolbox: (1) dual axes (2)legend

2012-03-22 Thread jpm miao
Hi, I have three time series and I would like to plot them on the same graph such that two of them share left y-axis and the third uses right y-axis. rm(list=ls()) library(zoo) x1 <- read.csv(file="120322DBCdata.csv", header=TRUE) x1date<-as.yearqtr(1979)+seq(0,nrow(x1)-1)/4 x1zoo<-zoo(x1, x1d

[R] Any package recommended for time series graphics in R?

2012-03-21 Thread jpm miao
Hello, I would like to produce a few time series graphs with R. My data is usually quarterly or monthly. I sometimes need to have two y-axes, one at the left, the other right. Is there any toolbox producing nice looking time series graphs? Thanks, miao [[alternative HTML version d

Re: [R] A question on histogram - area much less than 1

2012-03-12 Thread jpm miao
at is so incommensurate with the > heights of the histogram bars? > >cheers, > >Rolf Turner > > > On 12/03/12 20:42, jpm miao wrote: > >> Hello, >> >>I have problem running the histogram function "hist". The area under >> the >>

[R] A question on histogram - area much less than 1

2012-03-12 Thread jpm miao
Hello, I have problem running the histogram function "hist". The area under the histogram is much lower than 1. Could anyone tell me what the problem is? Thanks, (The total number of observation is 992 (close to 1000), so the probability that 0https://stat.ethz.ch/mailman/listinfo/r-help PLE

Re: [R] How can I tabulate time series data (in RStudio or any other R editor)?

2012-02-21 Thread jpm miao
866.77333 70.110002.462.70319166.8733369.48.723.386667329466.58667 69.79.213.20 2012/2/17 jpm miao > Hello, > >I have a question on how to tabulate the time series data. I use > RStudio, but if can be done in any other R editor, it should work in > R

[R] Debugging using RStudio or any other R editor

2012-02-20 Thread jpm miao
Hello, I am using RStudio and have trouble finding out the problematic line in the presence of a bug. Could I view the line NUMBER which contains a bug? Is there any R editor able to do it? Thanks, Miao [[alternative HTML version deleted]] ___

[R] Questions on Data reading using zoo package

2012-02-20 Thread jpm miao
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 t

[R] How can I tabulate time series data (in RStudio or any other R editor)?

2012-02-16 Thread jpm miao
Hello, I have a question on how to tabulate the time series data. I use RStudio, but if can be done in any other R editor, it should work in RStudio as well. > a1<-11:22 > a1ts<-ts(a1, frequency=4, start=c(1978,1)) > a1ts Qtr1 Qtr2 Qtr3 Qtr4 1978 11 12 13 14 1979 15 16 17

Re: [R] How can we access element(s) of a time series object?

2012-02-16 Thread jpm miao
a1tsw[2:3][1] 14 15 > 2012/2/16 R. Michael Weylandt > ?window may help. > > Michael > > On Thu, Feb 16, 2012 at 3:08 AM, jpm miao wrote: > > Hello, > > > > Let us convert a vector to a time series object starting in 1978Q1: > > FRW<-ts(FRW0, freq

[R] How can we access element(s) of a time series object?

2012-02-16 Thread jpm miao
Hello, Let us convert a vector to a time series object starting in 1978Q1: FRW<-ts(FRW0, frequency=4, start=c(1978,1)) FRW[3:6] represents the data from 1978Q3 to 1979Q2. Could we access the data by the time (1978Q3 to 1979Q2) instead of FRW[3:6]? Thanks, miao [[alternative

[R] A question on p-value of Unit Root Tests using “urca” toolbox

2012-02-07 Thread jpm miao
A question on p-value of Unit Root Tests using “urca” toolbox There’s a function “punitroot” on unit root probability value punitroot(q, N = Inf, trend = c("c", "nc", "ct", "ctt"), statistic = c("t", "n"), na.rm = FALSE) To my knowledge, “c” means “const” or intercept, “nc” means no const

[R] A question on Unit Root Test using "urca" toolbox

2012-02-02 Thread jpm miao
Hello, I have a question on unit root test with urca toolbox. First, to run a unit root test with lags selected by BIC, I type: > CPILD4UR<-ur.df(x1$CPILD4[5:nr1], type ="drift", lags=12, selectlags ="BIC") > summary(CPILD4UR) The results indicate that the optimal lags selected by BIC

<    1   2