[R] getting a timeseries element into a string
Ron Burns
rrburns at cox.net
Mon Jul 13 04:47:42 CEST 2009
Here is what I do:
R> library(fBasics)
R> ts<-dummyDailySeries(x = rnorm(365), units = NULL, zone = "",
FinCenter ="")
R> class(ts)
[1] "timeSeries"
attr(,"package")
[1] "timeSeries"
R> (s <- as.character(time(ts)[1]))
[1] "1970-01-01"
R> class(s)
[1] "character"
tradenet wrote:
> I added a reproducible example to my question...
>
> ts<-dummyDailySeries(x = rnorm(365), units = NULL, zone = "", FinCenter =
> "")
>
>
>> (ts[1,0]) #returns first date in return series
>>
> GMT
>
> 1970-01-01
>
>
>> ttt<-(sprintf("%s",ts[1,0]))
>>
>
>
>> print(ttt)
>>
> character(0)
>
>
>> ttt<-(ts[1,0])
>>
>
>
>> print(ttt)
>>
> GMT
>
> 1970-01-01
>
> what I want to get is a string containing "1970-01-01"
>
> Thank you.
>
>
>
>
>
>
>
> tradenet wrote:
>
>> I have a timeseries object, ts, and want to get the first date in the
>> series into a string so I can concatenate it with a SQL query. Input and
>> output are shown below. I must be missing something very basic, but I
>> can't seem to pry the data ("2008-07-01") into a string variable. Any
>> suggestions would be appreciated.
>>
>> Thank you,
>>
>> Andrew
>>
>> =====script:
>> class(ts)
>> (ts[1,0]) #returns first date in return series
>> ttt<-(sprintf("%s",ts[1,0]))
>> print(ttt)
>>
>> =====output:
>>
>>
>>
>>> class(ts)
>>>
>> [1] "timeSeries"
>> attr(,"package")
>> [1] "timeSeries"
>>
>>
>>> (ts[1,0]) #returns first date in return series
>>>
>> GMT
>>
>> 2008-07-01
>>
>>
>>> ttt<-(sprintf("%s",ts[1,0]))
>>>
>>> print(ttt)
>>>
>> character(0)
>>
>>
>>
>>
>>
>
>
--
R. R. Burns
Physicist (Retired)
Oceanside, CA
More information about the R-help
mailing list