Try it. We get rid of the inconvenience columns and specify the time index format, then convert to xts and use the dailyReturn function:
Lines <- "Symbol Series Date Prev.Close Open.Price High.Price Low.Price 1 XXX EQ 25-Aug-2004 850.00 1198.70 1198.70 979.00 2 XXX EQ 26-Aug-2004 987.95 992.00 997.00 975.30" library(quantmod) # this also pulls in xts & zoo z <- read.zoo(textConnection(Lines), format = "%d-%b-%Y", colClasses = rep(c(NA, "NULL", NA), c(1, 2, 5))) x <- as.xts(z) dailyReturn(x)
Of course, textConnection(Lines) is to save the example by itself and actually replace it with something like "myfile.dat" .
source share