gatherPrices | R Documentation |
Convenience function to gather data from one xts
or data.table
with at least "DT"
, and d columns containing price data to a "DT"
, "SYMBOL"
, and "PRICE"
column. This function the opposite of spreadPrices
.
gatherPrices(data)
data |
An |
a data.table
with columns DT
, SYMBOL
, and PRICE
Emil Sjoerup
spreadPrices
## Not run: library(data.table) data1 <- copy(sampleTData)[, `:=`(PRICE = PRICE * runif(.N, min = 0.99, max = 1.01), DT = DT + runif(.N, 0.01, 0.02))] data2 <- copy(sampleTData)[, SYMBOL := 'XYZ'] dat1 <- rbind(data1[, list(DT, SYMBOL, PRICE)], data2[, list(DT, SYMBOL, PRICE)]) setkeyv(dat1, c("DT", "SYMBOL")) dat1 dat <- spreadPrices(dat1) # Easy to use for realized measures dat dat <- gatherPrices(dat) dat all.equal(dat1, dat) # We have changed to RM format and back. ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.