This code works despite the convolutions so I can live with what follows.
It progresses from a CSV file, to a dataframe, to a list back to a dataframe, then to xts/ zoo.
Is there any easier and shorter way for subtracting two vectors?
library(xts)
#Step 1 CSV
dat<-read.csv("table(3).csv")
#first row in that file
# Date Open High Low Close Volume Adj.Close
#1 2014-04-17 21.85 21.91 21.75 21.86 47892800 21.86
#
class(dat)
#[1] "data.frame"
# Step 2
h<-subset(dat,select=c(High))
l<-subset(dat,select=c(Low))
d<-subset(dat,select=c(Date))
diff<-h-l
#Step 3
new<-c(d,h,l,diff)
class(new)
#[1] "list"
new2<-as.data.frame(new)
class(new2)
#[1] "data.frame"
#Step 4
new2.xts <- xts(x=new2[,-1],order.by= as.POSIXct(new2$Date))
class(new2.xts)
#[1] "xts" "zoo"