[R-SIG-Finance] stuck on data
Josh Ulrich
josh.m.ulrich at gmail.com
Thu Dec 25 00:43:03 CET 2008
On Wed, Dec 24, 2008 at 4:56 PM, zubin <binabina at bellsouth.net> wrote:
>> hello, need help with R in converting this data frame i received into
>> quantmod.
>>
>> Its a panel data set, (longitudinal or repeated measures) for an
>> econometrics project. I need to convert this data frame to something
>> quantmod can use, I would like access to all the time series
>> functions in R - plotting like in quantmod for example. However, its
>> not open,high,low,close - its
>> just one data point per time increment.
>>
You can use plot.xts, or plot.zoo (since xts extends zoo).
>> i researched and this led me to xts, but i can't figure out how to
>> link the data set below to xts? the as.Date is confusing - what is
>> as.Date(paste(DF$d, DF$b, DF$Y), "%d %b %Y"), i can't find any info on
>> what d, b, and Y are? what happens if i needed by the minute data,
>> less than day.
>>
The See Also section of ?as.Date specifically references ?strptime for
how to specify date formats (the second argument to as.Date). See the
Details section of ?strptime.
>> data frame looks like below, date comes in as a factor variable and
>> the others as int. I need to link the year, month,day to a time
>> class, or even the date below if possible, but its a Factor?
>>
You don't say how you read the data into R. Assuming you use
read.table, you need to set the argument stringsAsFactors = FALSE.
Then you could do something like:
x <- xts(DF, as.Date(DF[,"date"],"%d%b%Y")) # Assuming your date
column is in that format
>> so any help or an example of converting panel data frames to quantmod
>> would be appreciated.
>>
>> 'data.frame': 4048 obs. of 214 variables:
>> $ Store_nbr : int 177 177 177 177 177 177 177
>> 177 177 177 ...
>> $ year : int 2007 2007 2007 2007 2007
>> 2007 2007 2007 2007 2007 ...
>> $ month : int 9 9 9 9 9 9 9 9 9 9 ...
>> $ day : int 14 15 16 17 18 19 20 21 22
>> 23 ...
>> $ date : Factor w/ 506 levels
>> "01APR2008","01AUG2008",..: 224 241 258 275 292 309 326 343 360 377 ...
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>
HTH,
Josh
--
http://quantemplation.blogspot.com
More information about the R-SIG-Finance
mailing list