[R-SIG-Finance] stuck on data
Gabor Grothendieck
ggrothendieck at gmail.com
Thu Dec 25 02:04:19 CET 2008
Assume the original file looked like this:
Lines <- "Store_nbr year month day date
177 2007 9 14 01APR2008
177 2007 9 14 01AUG2008"
# and you were given this data frame, DF:
DF <- read.table(textConnection(Lines), header = TRUE)
# then try this to plot Store_nbr
st <- read.zoo(DF, index.column = 5, format = "%d%b%Y")
plot(st$Store_nbr)
# or if you meant you were given the file, not DF directly:
library(zoo)
z <- read.zoo(textConnection(Lines), header = TRUE, index.column = 5,
format = "%d%b%Y")
plot(z$Store_nbr)
See ?read.zoo, ?plot.zoo and the 3 zoo vignettes. Also R News 4/1
has info on dates.
On Wed, Dec 24, 2008 at 5: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.
>>
>> 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.
>>
>> 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?
>>
>> 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.
>
More information about the R-SIG-Finance
mailing list