Hi,
I have a dataframe of trading dates along with the corresponding prices.
I need to convert this into a time series object. How do I do this with
my price values being the time series object and the dates/time being
the trading dates.
BR, Shubha
[[alternative HTML version
You can use the 'ts' function.
Example
df - ts(your_data_frame,
start=c(1990,1), #The initial date of your data
end=c(2000,12), #The final date of your data or
frequency=12)#The frequency of your data, so you don't need of
the 'end' argument
See ?ts and ?as.ts
Hi,
I am trying to convert a dataset (dataframe) into time series object using ts
function in stats package. My dataset is as follows:
df
[1] 11.08 7.08 7.08 6.08 6.08 6.08 23.08 32.08 8.08 11.08 6.08 13.08
13.83 16.83 19.83 8.83 20.83 17.83
[19] 9.83 20.83 10.83 12.83
On Mon, 26 Jun 2006, Sachin J wrote:
I am trying to convert a dataset (dataframe) into time series object
using ts function in stats package. My dataset is as follows:
df
[1] 11.08 7.08 7.08 6.08 6.08 6.08 23.08 32.08 8.08 11.08 6.08 13.08
13.83 16.83 19.83 8.83 20.83 17.83
On Mon, 26 Jun 2006, Sachin J wrote:
Hi,
I am trying to convert a dataset (dataframe) into time series object
using ts function in stats package. My dataset is as follows:
df
[1] 11.08 7.08 7.08 6.08 6.08 6.08 23.08 32.08 8.08 11.08 6.08 13.08
13.83 16.83 19.83 8.83 20.83
Hi Achim,
I did the following:
df - read.csv(C:/data.csv, header=TRUE,sep=,,na.strings=NA, dec=,,
strip.white=TRUE)
Note: data.csv has 10 (V1...V10) columns.
df[1]
V1
111.08
2 7.08
3 7.08
4 6.08
5 6.08
6 6.08
7
We don't have data.csv so its still not ***reproducible*** by anyone
else. To be reproducible it means that anyone can copy the code
in your post, paste it into R and get the same answer.
Suggest you post the output of
dput(df)
and then post
dput - ...the output you got from dput(df)...
Now
You are right. The df is as follows:
df[1]
V1
111.08
2 7.08
3 7.08
4 6.08
5 6.08
6 6.08
723.08
832.08
9 8.08
10 11.08
116.08
12 13.08
13 13.83
14 16.83
15 19.83
16
Sorry I meant issue dput(df) and
post
df - ...the output your got from dput(df)...
...rest of your code...
Now its reproducible.
On 6/26/06, Gabor Grothendieck [EMAIL PROTECTED] wrote:
We don't have data.csv so its still not ***reproducible*** by anyone
else. To be reproducible it means
It seems I have problem in reading the data as dataframe. It is reading it as
factors. Here is the df
df - read.csv(C:/Data.csv,header=TRUE,sep=,,na.strings=NA, dec=,,
strip.white=TRUE)
dput(df)
df - structure(list(V1 = structure(c(2, 15, 15, 14, 14, 14, 12, 13,
+ 16, 2,
df[] - sapply(format(df), as.numeric)
will convert it to numeric but I think the real problem is the read.csv
statement. Do commas represent separators or decimals since
you have specified comma for both? Assuming it looks like:
A,B,C
1,2,3
4,5,6
just do:
DF - read.csv(Data.csv)
str(DF)
Hi Gabor,
You are correct. The real problem is with read.csv. I am not sure why? My
data looks
V1,V2,V3
11.08,21.73,13.08
7.08,37.73,6.08
7.08,11.73,21.08
I never had this problem earlier. Anyway I did
df - read.csv(Data.csv)
tsdata - ts((df),frequency = 12, start =
I think the problem is that you specified the decimal character to be
a comma so when it saw the dot it figured its not a number.
On 6/26/06, Sachin J [EMAIL PROTECTED] wrote:
Hi Gabor,
You are correct. The real problem is with read.csv. I am not sure why? My
data looks
V1,V2,V3
Sachin J [EMAIL PROTECTED] writes:
Hi Gabor,
You are correct. The real problem is with read.csv. I am not sure why? My
data looks
V1,V2,V3
11.08,21.73,13.08
7.08,37.73,6.08
7.08,11.73,21.08
read.csv(C:/Data.csv,header=TRUE,sep=,,na.strings=NA,
dec=,,
14 matches
Mail list logo