I have the following XML File:
<Company >
<shareprice>
<timeStamp> 12:00:00.01</timeStamp>
<Price> 25.02</Price>
</shareprice>
<shareprice>
<timeStamp> 12:00:00.02</timeStamp>
<Price> 15</Price>
</shareprice>
<shareprice>
<timeStamp> 12:00:01.025</timeStamp>
<Price> 15.02</Price>
</shareprice>
<shareprice>
<timeStamp> 12:00:01.031</timeStamp>
<Price> 18.25</Price>
</shareprice>
<shareprice>
<timeStamp> 12:00:01.039</timeStamp>
<Price> 18.54</Price>
</shareprice>
<shareprice>
<timeStamp> 12:00:01.050</timeStamp>
<Price> 16.52</Price>
</shareprice>
<shareprice>
<timeStamp> 12:00:02.01</timeStamp>
<Price> 17.50</Price>
</shareprice>
<shareprice>
<timeStamp> 12:00:03.01</timeStamp>
<Price> 25.02</Price>
</shareprice>
<shareprice>
<timeStamp> 12:00:05.02</timeStamp>
<Price> 30</Price>
</shareprice>
<shareprice>
<timeStamp> 12:00:11.025</timeStamp>
<Price> 32.25</Price>
</shareprice>
<shareprice>
<timeStamp> 12:00:12.031</timeStamp>
<Price> 26.05</Price>
</shareprice>
<shareprice>
<timeStamp> 12:00:15.039</timeStamp>
<Price> 18.54</Price>
</shareprice>
<shareprice>
<timeStamp> 12:00:19.050</timeStamp>
<Price> 16.52</Price>
</shareprice>
<shareprice>
<timeStamp> 12:01:02.01</timeStamp>
<Price> 17.50</Price>
</shareprice>
</Company>
And I also have the following R Code:
library (ggplot2)
library (XML)
df <- xmlToDataFrame(file.choose())
df$timeStamp <- strptime(as.character(df$timeStamp), "%H:%M:%OS")
df$Price <- as.numeric(as.character(df$Price))
sapply(df, class)
options("digits.secs"=3)
summary (df)
df$timeStamp <- df[1,"timeStamp"] + cumsum(runif(1:length(df$timeStamp))*60)
summary(df)
diff1 = 0
diff <- append(diff1,diff(df$Price))
summary (df$Price)
Ymin <- min(df$Price)
Ymax <- max(df$Price)
Ymedian <- median (df$Price)
Ymean <- mean(df$Price)
Ysd <- sd (df$Price)
sink (file="c:/xampp/htdocs/Sharedata.xml", type="output",split=FALSE)
cat("<graph caption=\"Share Data Wave\" subcaption=\"For Person's Name\" xAxisName=\"Time\" yAxisMinValue=\"-0.025\" yAxisName=\"Voltage\" decimalPrecision=\"5\" formatNumberScale=\"0\" numberPrefix=\"\" showNames=\"1\" showValues=\"0\" showAlternateHGridColor=\"1\" AlternateHGridColor=\"ff5904\" divLineColor=\"ff5904\" divLineAlpha=\"20\" alternateHGridAlpha=\"5\">\n")
cat(sprintf(" <set name=\"%s\" value=\"%f\" hoverText = \"The difference from last value: %s\" ></set>\n", df$timeStamp, df$Price, diff))
cat ("</graph>\n")
unlink("data.xml")
sink (file="c:/xampp/htdocs/Sharesstatistics.xml", type="output",split=FALSE)
cat (" <statistics>\n")
cat (sprintf(" <mean>%s</mean>\n", Ymean))
cat (sprintf(" <sd>%s</sd>\n",Ysd))
cat (sprintf(" <min>%s</min>\n", Ymin))
cat (sprintf(" <median>%s</median>\n",Ymedian))
cat (sprintf(" <max>%s</max>\n", Ymax))
cat (" </statistics>\n")
unlink("statistics.xml")
quit()
The R code does all I want and need it do on the full file. My question relates to how to let the user to select a range of the input file to analyse instead of the full file, how would this be done? For example if the user just wants the 2nd to 5th enteries of the input xml file and keep the same output as defined by the cat statements.
<shareprice>
<timeStamp> 12:00:00.02</timeStamp>
<Price> 15</Price>
</shareprice>
<shareprice>
<timeStamp> 12:00:01.025</timeStamp>
<Price> 15.02</Price>
</shareprice>
<shareprice>
<timeStamp> 12:00:01.031</timeStamp>
<Price> 18.25</Price>
</shareprice>
All help greatly appreciated.
Regards,
Anthony.