This seems like it should be a common thing, but all my searching comes up with half or unfinished answers.
I have a set of data in a csv. But the data is set up so
from http://r.789695.n4.nabble.com/Convert-tick-data-to-OHLC-td926206.html
ohlc <- function(ttime,tprice,tvolume,fmt) {
ttime.int <- format(ttime,fmt)
data.frame(time = ttime[tapply(1:length(ttime),ttime.int,function(x) {head(x,1)})],
.Open = tapply(tprice,ttime.int,function(x) {head(x,1)}),
.High = tapply(tprice,ttime.int,max),
.Low = tapply(tprice,ttime.int,min),
.Close = tapply(tprice,ttime.int,function(x) {tail(x,1)}),
.Volume = tapply(tvolume,ttime.int,function(x) {sum(x)}),
.Adjusted = tapply(tprice,ttime.int,function(x) {tail(x,1)}))
}