An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20081224/9e7c8d9f/attachment.pl>
stuck on data
4 messages · Joshua Ulrich, Gabor Grothendieck, zubin
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
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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20081224/2ab5e38a/attachment.pl>