How to have R selectively calculate values for certain variables? - r

My dataset is a list of 29 dataframes, such that one data frame looks like this:
>MergedData[[1]]
Date EUR.HIGH EUR.LOW EUR.CLOSE
1 2016-08-30 1.1192 1.1153 1.1161
2 2016-08-29 1.1208 1.1158 1.1189
3 2016-08-28 1.1341 1.1181 1.1198
4 2016-08-27 1.1341 1.1181 1.1198
5 2016-08-26 1.1341 1.1181 1.1198
6 2016-08-25 1.1298 1.1259 1.1285
7 2016-08-24 1.1312 1.1245 1.1264
So using this list, I calculated 'signals' in R with values of -2,1 and 0. I want R to do calculations and leave them in an output for variables that have values that aren't zero. Here's what my signal looks like in R:
>price.break
EUR JPY GBP CHF AUD CAD NZD SEK
2016-02-19 NA NA NA NA NA NA NA NA
2016-02-20 0 -2 0 0 -2 0 0 0
2016-02-21 0 0 0 0 0 0 0 0
>ma.sig
EUR JPY GBP CHF AUD CAD NZD SEK
2016-02-19 NA NA NA NA NA NA NA NA
2016-02-20 0 1 0 0 1 0 0 0
2016-02-21 0 0 0 0 0 0 0 0
Since we have that both JPY and AUD have returned non-zero signals, I want R to calculate an output table that looks like this:
Currency Deviation from MA RSI
JPY
AUD
Here is my (rather terrible) attempt at trying to have R do this:
new.trend <- function(x)
{
ret <- as.list(rep(NA, length(x)))
for (i in 1:length(MergedData)){
x <- MergedData[[i]]
x <- xts(x[,-1], order.by=x[,1])
ma.sig <- ma.crossover(x)
pricebreak <- price.channel(x)
sig.col <- col(x)[which(!ma.sig[,i]&ma.sig[,i-1)]==0)&which(!pricebreak[,i]&pricebreak[,i-1]==0)]
sig.row <- row(x)[which(!ma.sig[,i]&ma.sig[,i-1)]==0)&which(!pricebreak[,i]&pricebreak[,i-1]==0)]
ma20 <- SMA(x[sig.row, sig.col], n=20)
ma50 <- SMA(x[sig.row, sig.col], n=50)
RSI <- RSI(x[sig.row, sig.col], n=14)
dev20 <- x[sig.row, sig.col]-ma20[sig.row, sig.col]/x[sig.row, sig.col]*100
dev50 <- x[sig.row, sig.col]-ma50[sig.row, sig.col]/x[sig.row, sig.col]*100
ret[[i]] <- merge(RSI, 20dev, 50dev)
}
na.omit(do.call(merge,ret))
}
With sig.col and sig.row, I'm hoping to extract the exact row/column number in order to selectively calculate the instances where we get nonnegative signals. I get the error saying 'incorrect number dimensions', and I have a strong feeling what I'm doing isn't correct anyway.
ma.crossover and pricebreak are just functions that calculate the following:
ma.crossover<- function(MergedData){
ma <- as.list(rep(NA, length(MergedData)))
for(i in 1:length(MergedData)) {
x <- MergedData[[i]]
x <- xts(x[,-1], order.by=x[,1])
ma20 <- SMA(x[,3], n=20)
ma50 <- SMA(x[,3], n=50)
ma[[i]] <- sign(ma20 - ma50)
}
na.omit(do.call(merge, ma))
}
##price channel
price.channel <- function(MergedData)
{
ret <- as.list(rep(NA, length(MergedData)))
for (i in 1:length(MergedData)) {
x<- MergedData[[i]]
x <- xts(x[,-1], order.by=x[,1])
high <- runMax(x[,2], 20)
low <- runMin(x[,3], 20)
mid <- (high+low)/2
channel <- cbind(high, mid, low)
ret[[i]] <- merge(sign(high-x[,5]), sign(x[,5]-low))
}
na.omit(do.call(merge, ret))
}
I've been stuck on this for some time, so comments or feedback would be very much appreciated. Here's a sample of my dput, if that helps:
tzone = "", class = c("POSIXct",
"POSIXt")), PHP.OPEN = c(46.385, 46.283, 46.283, 46.283,
46.283, 46.33, 46.45, 46.45, 46.5, 46.29, 46.29, 46.29, 46.235,
46.28, 46.225, 46.445, 46.455, 46.455, 46.455, 46.365, 46.73,
46.85, 46.423, 46.05, 46.05, 46.05, 46.975, 46.03, 46.035,
46.915, 47.017, 47.017, 47.017, 47.05, 46.825, 47.105, 47.12,
47, 47, 47, 47.055, 46.015, 46.725, 46.675, 46.671, 46.671,
46.671, 47.019, 47, 47.055, 47.033, 47, 47, 47, 46.85, 46.765,
46.765, 46.753, 46.465, 46.465, 46.465, 46.035, 46.49, 45.93,
46.955, 46.51, 46.51, 46.51, 46.475, 46.365, 46.31, 46.3,
44.623, 44.623, 44.623, 46.285, 46.31, 46.073, 46.07, 46.06,
46.06, 46.06, 45.859, 46, 45.728, 46.2, 46.452, 46.452, 46.452,
46.53, 46.64, 46.653, 46.69, 46.614, 46.614, 46.614, 46.429,
46.63, 46.788, 46.69, 46.714, 46.714, 46.714, 46.705, 46.465,
46.325, 46.055, 46.55, 46.55, 46.55, 46.458, 46.53, 46.753,
47.085, 47.085, 47.085, 47.085, 47.118, 46.595, 46.845, 46.225,
46.66, 46.66, 46.66, 46.722, 46.64, 46.728, 46.683, 46.285,
46.285, 46.285, 46.224, 46.04, 46.055, 46.06, 46.049, 46.049,
46.049, 46.154, 45.903, 46.017, 46, 46.12, 46.12, 46.12,
46.07, 46.165, 46.153, 45, 45.95, 45.95, 45.95, 45.91, 46.02,
46.235, 46.325, 46.227, 46.227, 46.227, 46.227, 46.227, 46.16,
46, 46.168, 46.168, 46.168, 46.357, 46.475, 46.61, 46.439,
46.595, 46.595, 46.595, 46.653, 46.835, 46.285, 46.772, 46.861,
46.861, 46.861, 47.02, 47.225, 47.3, 47.525, 47.076, 47.076,
47.076, 47.62, 47.613, 47.575, 47.585, 47.552, 47.552, 47.552,
47.51, 47.45, 47.403, 47.435, 47.45, 47.45, 47.45, 47.375,
47.445, 47, 47.665, 47.665, 47.665, 47.665, 47.719, 47.825,
47.67, 47.623, 47.615, 47.615, 47.615, 47.717, 47.809, 47.869,
47.72, 47.8, 47.8, 47.8, 47.695, 47.67, 47.586, 47.635, 47.63,
47.63, 47.63, 47.55, 47.335, 47.2, 47.233, 46.92, 46.92,
46.92, 46.98, 46.82, 46.875, 47, 47.17, 47.17, 47.17), PHP.HIGH = c(46.535,
46.438, 46.438, 46.438, 46.438, 46.583, 46.645, 46.59, 46.702,
46.488, 46.488, 46.488, 46.41, 46.88, 46.88, 46.77, 46.865,
46.865, 46.865, 46.8, 46.865, 46.975, 47.02, 47.04, 47.04,
47.04, 47.075, 47.358, 47.487, 47.03, 47.135, 47.135, 47.135,
47.18, 47.228, 47.24, 47.228, 47.155, 47.155, 47.155, 47.23,
47.158, 46.96, 46.89, 47.055, 47.055, 47.055, 47.22, 47.435,
47.49, 47.32, 47.585, 47.585, 47.585, 47.112, 47.345, 47.345,
46.895, 47.065, 47.065, 47.065, 47.935, 47.98, 47.95, 47.183,
46.975, 46.975, 46.975, 46.587, 46.64, 46.388, 46.445, 46.475,
46.475, 46.475, 46.455, 46.479, 47.065, 46.222, 46.155, 46.155,
46.155, 46.388, 46.12, 46.265, 46.45, 46.982, 46.982, 46.982,
46.615, 46.79, 47.065, 46.825, 46.71, 46.71, 46.71, 46.788,
46.889, 46.925, 46.86, 46.86, 46.86, 46.86, 46.947, 46.705,
46.457, 46.655, 46.8, 46.8, 46.8, 46.715, 46.75, 47.205,
47.385, 47.385, 47.385, 47.385, 47.245, 47.132, 47.75, 47.041,
46.964, 46.964, 46.964, 46.878, 46.842, 46.94, 46.874, 46.68,
46.68, 46.68, 46.46, 46.225, 46.16, 46.2, 46.25, 46.25, 46.25,
46.306, 46.487, 46.14, 46.18, 46.266, 46.266, 46.266, 46.17,
46.338, 46.295, 46.105, 47.02, 47.02, 47.02, 46.085, 46.262,
46.439, 46.537, 46.463, 46.463, 46.463, 46.463, 46.463, 46.39,
46.577, 46.379, 46.379, 46.379, 46.58, 46.925, 46.83, 46.607,
46.795, 46.795, 46.795, 46.855, 47.025, 47.035, 46.925, 47.125,
47.125, 47.125, 47.252, 47.307, 47.5, 47.605, 47.603, 47.603,
47.603, 47.62, 47.717, 47.66, 47.705, 47.905, 47.905, 47.905,
47.595, 47.695, 47.59, 47.555, 47.74, 47.74, 47.74, 47.488,
47.632, 47.795, 47.757, 47.757, 47.757, 47.757, 47.8, 47.925,
47.79, 47.74, 47.775, 47.775, 47.775, 47.945, 47.995, 48.005,
47.9, 47.911, 47.911, 47.911, 47.958, 47.895, 47.755, 47.885,
47.78, 47.78, 47.78, 47.748, 47.55, 47.46, 47.335, 47.173,
47.173, 47.173, 47.14, 47.062, 47.188, 47.158, 47.17, 47.17,
47.17), PHP.LOW = c(46.385, 46.283, 46.283, 46.283, 46.283,
46.33, 46.45, 46.45, 46.5, 46.29, 46.29, 46.29, 46.235, 46.28,
46.225, 46.445, 46.455, 46.455, 46.455, 46.365, 46.73, 46.85,
46.423, 46.05, 46.05, 46.05, 46.975, 46.03, 46.035, 46.915,
47.017, 47.017, 47.017, 47.05, 46.825, 47.105, 47.12, 47,
47, 47, 47.055, 46.015, 46.725, 46.675, 46.671, 46.671, 46.671,
47.019, 47, 47.055, 47.033, 47, 47, 47, 46.85, 46.765, 46.765,
46.753, 46.465, 46.465, 46.465, 46.035, 46.49, 45.93, 46.955,
46.51, 46.51, 46.51, 46.475, 46.365, 46.31, 46.3, 44.623,
44.623, 44.623, 46.285, 46.31, 46.073, 46.07, 46.06, 46.06,
46.06, 45.859, 46, 45.728, 46.2, 46.452, 46.452, 46.452,
46.53, 46.64, 46.653, 46.69, 46.614, 46.614, 46.614, 46.429,
46.63, 46.788, 46.69, 46.714, 46.714, 46.714, 46.705, 46.465,
46.325, 46.055, 46.55, 46.55, 46.55, 46.458, 46.53, 46.753,
47.085, 47.085, 47.085, 47.085, 47.118, 46.595, 46.845, 46.225,
46.66, 46.66, 46.66, 46.722, 46.64, 46.728, 46.683, 46.285,
46.285, 46.285, 46.224, 46.04, 46.055, 46.06, 46.049, 46.049,
46.049, 46.154, 45.903, 46.017, 46, 46.12, 46.12, 46.12,
46.07, 46.165, 46.153, 45, 45.95, 45.95, 45.95, 45.91, 46.02,
46.235, 46.325, 46.227, 46.227, 46.227, 46.227, 46.227, 46.16,
46, 46.168, 46.168, 46.168, 46.357, 46.475, 46.61, 46.439,
46.595, 46.595, 46.595, 46.653, 46.835, 46.285, 46.772, 46.861,
46.861, 46.861, 47.02, 47.225, 47.3, 47.525, 47.076, 47.076,
47.076, 47.62, 47.613, 47.575, 47.585, 47.552, 47.552, 47.552,
47.51, 47.45, 47.403, 47.435, 47.45, 47.45, 47.45, 47.375,
47.445, 47, 47.665, 47.665, 47.665, 47.665, 47.719, 47.825,
47.67, 47.623, 47.615, 47.615, 47.615, 47.717, 47.809, 47.869,
47.72, 47.8, 47.8, 47.8, 47.695, 47.67, 47.586, 47.635, 47.63,
47.63, 47.63, 47.55, 47.335, 47.2, 47.233, 46.92, 46.92,
46.92, 46.98, 46.82, 46.875, 47, 47.17, 47.17, 47.17), PHP.CLOSE = c(46.46,
46.36, 46.36, 46.36, 46.36, 46.345, 46.535, 46.45, 46.58,
46.45, 46.45, 46.45, 46.28, 46.41, 46.88, 46.455, 46.6, 46.6,
46.6, 46.79, 46.75, 46.85, 46.835, 46.9, 46.9, 46.9, 47.02,
47.035, 46.961, 46.94, 47.11, 47.11, 47.11, 47.07, 47.18,
47.14, 47.15, 47.12, 47.12, 47.12, 47.077, 46.725, 46.94,
46.714, 46.85, 46.85, 46.85, 47.05, 47.21, 47.321, 47.31,
47.125, 47.125, 47.125, 47, 47.03, 47.03, 46.775, 46.915,
46.915, 46.915, 47.085, 46.965, 46.895, 47.03, 46.95, 46.95,
46.95, 46.51, 46.475, 46.38, 46.335, 46.425, 46.425, 46.425,
46.43, 46.43, 46.31, 46.08, 46.13, 46.13, 46.13, 46.055,
46.01, 46.11, 46.225, 46.465, 46.465, 46.465, 46.53, 46.64,
46.75, 46.75, 46.635, 46.635, 46.635, 46.69, 46.785, 46.92,
46.788, 46.75, 46.75, 46.75, 46.8, 46.66, 46.42, 46.46, 46.555,
46.555, 46.555, 46.647, 46.555, 46.757, 47.09, 47.09, 47.09,
47.09, 47.24, 47.08, 46.89, 46.965, 46.89, 46.89, 46.89,
46.77, 46.78, 46.76, 46.85, 46.645, 46.645, 46.645, 46.44,
46.225, 46.093, 46.185, 46.065, 46.065, 46.065, 46.25, 46.085,
46.018, 46.122, 46.135, 46.135, 46.135, 46.1, 46.2, 46.26,
46.08, 46.015, 46.015, 46.015, 46.07, 46.028, 46.35, 46.34,
46.395, 46.395, 46.395, 46.395, 46.395, 46.285, 46.33, 46.36,
46.36, 46.36, 46.38, 46.785, 46.83, 46.595, 46.62, 46.62,
46.62, 46.695, 46.855, 46.958, 46.92, 46.946, 46.946, 46.946,
47.125, 47.298, 47.35, 47.558, 47.515, 47.515, 47.515, 47.62,
47.625, 47.635, 47.619, 47.665, 47.665, 47.665, 47.55, 47.45,
47.573, 47.45, 47.74, 47.74, 47.74, 47.45, 47.47, 47.671,
47.665, 47.665, 47.665, 47.665, 47.775, 47.86, 47.685, 47.69,
47.65, 47.65, 47.65, 47.743, 47.815, 47.997, 47.89, 47.805,
47.805, 47.805, 47.935, 47.89, 47.67, 47.706, 47.745, 47.745,
47.745, 47.64, 47.542, 47.45, 47.269, 47.158, 47.158, 47.158,
47.01, 47.025, 46.89, 47.125, 47.17, 47.17, 47.17), PHP.LAST = c(46.46,
46.36, 46.36, 46.36, 46.36, 46.345, 46.535, 46.45, 46.58,
46.45, 46.45, 46.45, 46.28, 46.41, 46.88, 46.455, 46.6, 46.6,
46.6, 46.79, 46.75, 46.85, 46.835, 46.9, 46.9, 46.9, 47.02,
47.035, 46.961, 46.94, 47.11, 47.11, 47.11, 47.07, 47.18,
47.14, 47.15, 47.12, 47.12, 47.12, 47.077, 46.725, 46.94,
46.714, 46.85, 46.85, 46.85, 47.05, 47.21, 47.321, 47.31,
47.125, 47.125, 47.125, 47, 47.03, 47.03, 46.775, 46.915,
46.915, 46.915, 47.085, 46.965, 46.895, 47.03, 46.95, 46.95,
46.95, 46.51, 46.475, 46.38, 46.335, 46.425, 46.425, 46.425,
46.43, 46.43, 46.31, 46.08, 46.13, 46.13, 46.13, 46.055,
46.01, 46.11, 46.225, 46.465, 46.465, 46.465, 46.53, 46.64,
46.75, 46.75, 46.635, 46.635, 46.635, 46.69, 46.785, 46.92,
46.788, 46.75, 46.75, 46.75, 46.8, 46.66, 46.42, 46.46, 46.555,
46.555, 46.555, 46.647, 46.555, 46.757, 47.09, 47.09, 47.09,
47.09, 47.24, 47.08, 46.89, 46.965, 46.89, 46.89, 46.89,
46.77, 46.78, 46.76, 46.85, 46.645, 46.645, 46.645, 46.44,
46.225, 46.093, 46.185, 46.065, 46.065, 46.065, 46.25, 46.085,
46.018, 46.122, 46.135, 46.135, 46.135, 46.1, 46.2, 46.26,
46.08, 46.015, 46.015, 46.015, 46.07, 46.028, 46.35, 46.34,
46.395, 46.395, 46.395, 46.395, 46.395, 46.285, 46.33, 46.36,
46.36, 46.36, 46.38, 46.785, 46.83, 46.595, 46.62, 46.62,
46.62, 46.695, 46.855, 46.958, 46.92, 46.946, 46.946, 46.946,
47.125, 47.298, 47.35, 47.558, 47.515, 47.515, 47.515, 47.62,
47.625, 47.635, 47.619, 47.665, 47.665, 47.665, 47.55, 47.45,
47.573, 47.45, 47.74, 47.74, 47.74, 47.45, 47.47, 47.671,
47.665, 47.665, 47.665, 47.665, 47.775, 47.86, 47.685, 47.69,
47.65, 47.65, 47.65, 47.743, 47.815, 47.997, 47.89, 47.805,
47.805, 47.805, 47.935, 47.89, 47.67, 47.706, 47.745, 47.745,
47.745, 47.64, 47.542, 47.45, 47.269, 47.158, 47.158, 47.158,
47.01, 47.025, 46.89, 47.125, 47.17, 47.17, 47.17)), .Names = c("Date",
"PHP.OPEN", "PHP.HIGH", "PHP.LOW", "PHP.CLOSE", "PHP.LAST"
), row.names = c(NA, -243L), class = "data.frame"), structure(list(
Date = structure(c(1472533200, 1472446800, 1472360400,
1472274000, 1472187600, 1472101200, 1472014800, 1471928400,
1471842000, 1471755600, 1471669200, 1471582800, 1471496400,
1471410000, 1471323600, 1471237200, 1471150800, 1471064400,
1470978000, 1470891600, 1470805200, 1470718800, 1470632400,
1470546000, 1470459600, 1470373200, 1470286800, 1470200400,
1470114000, 1470027600, 1469941200, 1469854800, 1469768400,
1469682000, 1469595600, 1469509200, 1469422800, 1469336400,
1469250000, 1469163600, 1469077200, 1468990800, 1468904400,
1468818000, 1468731600, 1468645200, 1468558800, 1468472400,
1468386000, 1468299600, 1468213200, 1468126800, 1468040400,
1467954000, 1467867600, 1467781200, 1467694800, 1467608400,
1467522000, 1467435600, 1467349200, 1467262800, 1467176400,
1467090000, 1467003600, 1466917200, 1466830800, 1466744400,
1466658000, 1466571600, 1466485200, 1466398800, 1466312400,
1466226000, 1466139600, 1466053200, 1465966800, 1465880400,
1465794000, 1465707600, 1465621200, 1465534800, 1465448400,
1465362000, 1465275600, 1465189200, 1465102800, 1465016400,
1464930000, 1464843600, 1464757200, 1464670800, 1464584400,
1464498000, 1464411600, 1464325200, 1464238800, 1464152400,
1464066000, 1463979600, 1463893200, 1463806800, 1463720400,
1463634000, 1463547600, 1463461200, 1463374800, 1463288400,
1463202000, 1463115600, 1463029200, 1462942800, 1462856400,
1462770000, 1462683600, 1462597200, 1462510800, 1462424400,
1462338000, 1462251600, 1462165200, 1462078800, 1461992400,
1461906000, 1461819600, 1461733200, 1461646800, 1461560400,
1461474000, 1461387600, 1461301200, 1461214800, 1461128400,
1461042000, 1460955600, 1460869200, 1460782800, 1460696400,
1460610000, 1460523600, 1460437200, 1460350800, 1460264400,
1460178000, 1460091600, 1460005200, 1459918800, 1459832400,
1459746000, 1459659600, 1459573200, 1459486800, 1459400400,
1459314000, 1459227600, 1459141200, 1459054800, 1458968400,
1458882000, 1458795600, 1458709200, 1458622800, 1458536400,
1458450000, 1458363600, 1458277200, 1458190800, 1458104400,
1458018000, 1457931600, 1457848800, 1457762400, 1457676000,
1457589600, 1457503200, 1457416800, 1457330400, 1457244000,
1457157600, 1457071200, 1456984800, 1456898400, 1456812000,
1456725600, 1456639200, 1456552800, 1456466400, 1456380000,
1456293600, 1456207200, 1456120800, 1456034400, 1455948000,
1455861600, 1455775200, 1455688800, 1455602400, 1455516000,
1455429600, 1455343200, 1455256800, 1455170400, 1455084000,
1454997600, 1454911200, 1454824800, 1454738400, 1454652000,
1454565600, 1454479200, 1454392800, 1454306400, 1454220000,
1454133600, 1454047200, 1453960800, 1453874400, 1453788000,
1453701600, 1453615200, 1453528800, 1453442400, 1453356000,
1453269600, 1453183200, 1453096800, 1453010400, 1452924000,
1452837600, 1452751200, 1452664800, 1452578400, 1452492000,
1452405600, 1452319200, 1452232800, 1452146400, 1452060000,
1451973600, 1451887200, 1451800800, 1451714400, 1451628000
), tzone = "", class = c("POSIXct", "POSIXt")), THB.OPEN = c(34.53,
34.596, 34.506, 34.506, 34.506, 34.539, 34.573, 34.564,
34.607, 34.528, 34.528, 34.528, 34.531, 34.577, 34.52,
34.577, 34.696, 34.696, 34.696, 34.731, 34.738, 34.911,
34.901, 34.796, 34.796, 34.796, 34.886, 34.739, 34.74,
34.72, 34.8, 34.8, 34.8, 34.84, 34.951, 34.98, 34.905,
34.87, 34.87, 34.87, 34.95, 34.97, 34.931, 34.918, 34.907,
34.907, 34.907, 35.029, 35.13, 35.103, 35.049, 35.169,
35.169, 35.169, 35.145, 35.149, 35.012, 35.011, 35.06,
35.06, 35.06, 35.097, 35.175, 35.238, 35.257, 35.114,
35.114, 35.114, 35.146, 35.173, 35.15, 35.162, 35.225,
35.225, 35.225, 35.151, 35.24, 35.12, 35.16, 35.147,
35.147, 35.147, 35.085, 35.189, 35.217, 35.26, 35.545,
35.545, 35.545, 35.57, 35.64, 35.691, 35.69, 35.56, 35.56,
35.56, 35.571, 35.625, 35.664, 35.56, 35.622, 35.622,
35.622, 35.641, 35.486, 35.32, 35.341, 35.311, 35.311,
35.311, 35.217, 35.19, 35.193, 35.09, 35.126, 35.126,
35.126, 35.075, 34.99, 34.83, 34.83, 34.885, 34.885,
34.885, 35.007, 35.09, 35.08, 35.052, 35.02, 35.02, 35.02,
34.883, 34.825, 34.88, 35.01, 35.051, 35.051, 35.051,
35.024, 34.951, 35.005, 35.04, 35.09, 35.09, 35.09, 35.15,
35.214, 35.237, 35.12, 35.09, 35.09, 35.09, 35.159, 35.189,
35.323, 35.274, 35.265, 35.265, 35.265, 35.188, 34.917,
34.88, 34.85, 34.745, 34.745, 34.745, 34.77, 34.99, 35.07,
35.05, 35.064, 35.064, 35.064, 35.239, 35.287, 35.365,
35.349, 35.385, 35.385, 35.385, 35.476, 35.54, 35.588,
35.618, 35.63, 35.63, 35.63, 35.65, 35.69, 35.715, 35.717,
35.54, 35.54, 35.54, 35.537, 35.6, 35.59, 35.552, 35.228,
35.228, 35.228, 35.228, 35.3, 35.388, 35.495, 35.48,
35.48, 35.48, 35.55, 35.77, 35.579, 35.591, 35.684, 35.684,
35.684, 35.775, 35.77, 35.89, 35.925, 36.026, 36.026,
36.026, 36.235, 36.272, 36.26, 36.29, 36.28, 36.28, 36.28,
36.256, 36.237, 36.235, 36.25, 36.17, 36.17, 36.17, 36.226,
36.103, 36.08, 36.033, 36.02, 36.02, 36.02), THB.HIGH = c(34.655,
34.72, 34.601, 34.601, 34.601, 34.675, 34.69, 34.676,
34.764, 34.671, 34.671, 34.671, 34.69, 34.737, 34.65,
34.82, 34.86, 34.86, 34.86, 34.838, 34.967, 35.005, 35.065,
34.93, 34.93, 34.93, 35.039, 34.95, 34.84, 34.91, 34.92,
34.92, 34.92, 34.967, 35.074, 35.086, 35.08, 35, 35,
35, 35.088, 35.09, 35.04, 35.03, 35.085, 35.085, 35.085,
35.23, 35.257, 35.206, 35.225, 35.264, 35.264, 35.264,
35.239, 35.281, 35.198, 35.125, 35.16, 35.16, 35.16,
35.228, 35.295, 35.371, 35.435, 35.546, 35.546, 35.546,
35.244, 35.29, 35.24, 35.284, 35.356, 35.356, 35.356,
35.254, 35.39, 35.303, 35.295, 35.295, 35.295, 35.295,
35.24, 35.241, 35.327, 35.411, 35.64, 35.64, 35.64, 35.704,
35.77, 35.755, 35.8, 35.701, 35.701, 35.701, 35.68, 35.795,
35.787, 35.706, 35.736, 35.736, 35.736, 35.8, 35.625,
35.557, 35.461, 35.466, 35.466, 35.466, 35.34, 35.294,
35.267, 35.166, 35.193, 35.193, 35.193, 35.19, 35.184,
34.94, 34.934, 35.009, 35.009, 35.009, 35.16, 35.195,
35.222, 35.17, 35.095, 35.095, 35.095, 35.095, 34.949,
35.02, 35.11, 35.12, 35.12, 35.12, 35.211, 35.055, 35.07,
35.112, 35.234, 35.234, 35.234, 35.253, 35.31, 35.39,
35.29, 35.175, 35.175, 35.175, 35.262, 35.365, 35.44,
35.408, 35.365, 35.365, 35.365, 35.395, 35.13, 34.963,
34.952, 34.925, 34.925, 34.925, 34.975, 35.145, 35.15,
35.151, 35.26, 35.26, 35.26, 35.31, 35.393, 35.47, 35.495,
35.46, 35.46, 35.46, 35.559, 35.656, 35.655, 35.763,
35.707, 35.707, 35.707, 35.714, 35.759, 35.776, 35.781,
35.75, 35.75, 35.75, 35.63, 35.68, 35.671, 35.69, 35.64,
35.64, 35.64, 35.325, 35.428, 35.539, 35.612, 35.651,
35.651, 35.651, 35.755, 35.87, 35.771, 35.77, 35.861,
35.861, 35.861, 35.885, 35.874, 36.045, 36.055, 36.253,
36.253, 36.253, 36.29, 36.327, 36.325, 36.382, 36.374,
36.374, 36.374, 36.345, 36.338, 36.375, 36.345, 36.327,
36.327, 36.327, 36.35, 36.257, 36.177, 36.19, 36.033,
36.033, 36.033), THB.LOW = c(34.53, 34.596, 34.506, 34.506,
34.506, 34.539, 34.573, 34.564, 34.607, 34.528, 34.528,
34.528, 34.531, 34.577, 34.52, 34.577, 34.696, 34.696,
34.696, 34.731, 34.738, 34.911, 34.901, 34.796, 34.796,
34.796, 34.886, 34.739, 34.74, 34.72, 34.8, 34.8, 34.8,
34.84, 34.951, 34.98, 34.905, 34.87, 34.87, 34.87, 34.95,
34.97, 34.931, 34.918, 34.907, 34.907, 34.907, 35.029,
35.13, 35.103, 35.049, 35.169, 35.169, 35.169, 35.145,
35.149, 35.012, 35.011, 35.06, 35.06, 35.06, 35.097,
35.175, 35.238, 35.257, 35.114, 35.114, 35.114, 35.146,
35.173, 35.15, 35.162, 35.225, 35.225, 35.225, 35.151,
35.24, 35.12, 35.16, 35.147, 35.147, 35.147, 35.085,
35.189, 35.217, 35.26, 35.545, 35.545, 35.545, 35.57,
35.64, 35.691, 35.69, 35.56, 35.56, 35.56, 35.571, 35.625,
35.664, 35.56, 35.622, 35.622, 35.622, 35.641, 35.486,
35.32, 35.341, 35.311, 35.311, 35.311, 35.217, 35.19,
35.193, 35.09, 35.126, 35.126, 35.126, 35.075, 34.99,
34.83, 34.83, 34.885, 34.885, 34.885, 35.007, 35.09,
35.08, 35.052, 35.02, 35.02, 35.02, 34.883, 34.825, 34.88,
35.01, 35.051, 35.051, 35.051, 35.024, 34.951, 35.005,
35.04, 35.09, 35.09, 35.09, 35.15, 35.214, 35.237, 35.12,
35.09, 35.09, 35.09, 35.159, 35.189, 35.323, 35.274,
35.265, 35.265, 35.265, 35.188, 34.917, 34.88, 34.85,
34.745, 34.745, 34.745, 34.77, 34.99, 35.07, 35.05, 35.064,
35.064, 35.064, 35.239, 35.287, 35.365, 35.349, 35.385,
35.385, 35.385, 35.476, 35.54, 35.588, 35.618, 35.63,
35.63, 35.63, 35.65, 35.69, 35.715, 35.717, 35.54, 35.54,
35.54, 35.537, 35.6, 35.59, 35.552, 35.228, 35.228, 35.228,
35.228, 35.3, 35.388, 35.495, 35.48, 35.48, 35.48, 35.55,
35.77, 35.579, 35.591, 35.684, 35.684, 35.684, 35.775,
35.77, 35.89, 35.925, 36.026, 36.026, 36.026, 36.235,
36.272, 36.26, 36.29, 36.28, 36.28, 36.28, 36.256, 36.237,
36.235, 36.25, 36.17, 36.17, 36.17, 36.226, 36.103, 36.08,
36.033, 36.02, 36.02, 36.02), THB.CLOSE = c(34.558, 34.601,
34.565, 34.565, 34.565, 34.565, 34.618, 34.64, 34.67,
34.635, 34.635, 34.635, 34.605, 34.7, 34.575, 34.61,
34.81, 34.81, 34.81, 34.76, 34.751, 34.965, 34.974, 34.822,
34.822, 34.822, 34.927, 34.94, 34.75, 34.77, 34.83, 34.83,
34.83, 34.868, 34.97, 35.01, 35.05, 34.93, 34.93, 34.93,
34.995, 34.989, 35.01, 35.005, 34.94, 34.94, 34.94, 35.03,
35.16, 35.138, 35.11, 35.25, 35.25, 35.25, 35.173, 35.214,
35.134, 35.048, 35.086, 35.086, 35.086, 35.138, 35.23,
35.29, 35.35, 35.339, 35.339, 35.339, 35.173, 35.24,
35.173, 35.21, 35.235, 35.235, 35.235, 35.24, 35.25,
35.3, 35.18, 35.26, 35.26, 35.26, 35.21, 35.21, 35.23,
35.28, 35.629, 35.629, 35.629, 35.61, 35.67, 35.705,
35.75, 35.658, 35.658, 35.658, 35.6, 35.71, 35.73, 35.66,
35.679, 35.679, 35.679, 35.71, 35.6, 35.49, 35.37, 35.43,
35.43, 35.43, 35.32, 35.27, 35.236, 35.13, 35.149, 35.149,
35.149, 35.179, 35.184, 34.92, 34.841, 34.92, 34.92,
34.92, 35.02, 35.15, 35.16, 35.11, 35.04, 35.04, 35.04,
35.01, 34.86, 34.91, 35.03, 35.065, 35.065, 35.065, 35.12,
35.036, 35.02, 35.07, 35.12, 35.12, 35.12, 35.205, 35.256,
35.32, 35.263, 35.105, 35.105, 35.105, 35.185, 35.235,
35.426, 35.36, 35.27, 35.27, 35.27, 35.35, 35.118, 34.91,
34.89, 34.85, 34.85, 34.85, 34.78, 35.02, 35.132, 35.08,
35.16, 35.16, 35.16, 35.25, 35.32, 35.425, 35.42, 35.403,
35.403, 35.403, 35.51, 35.57, 35.625, 35.64, 35.64, 35.64,
35.64, 35.68, 35.7, 35.74, 35.755, 35.745, 35.745, 35.745,
35.548, 35.61, 35.61, 35.65, 35.58, 35.58, 35.58, 35.245,
35.36, 35.489, 35.51, 35.497, 35.497, 35.497, 35.56,
35.841, 35.76, 35.605, 35.73, 35.73, 35.73, 35.825, 35.79,
35.908, 36.021, 36.037, 36.037, 36.037, 36.263, 36.3,
36.27, 36.32, 36.366, 36.366, 36.366, 36.313, 36.25,
36.33, 36.28, 36.307, 36.307, 36.307, 36.285, 36.22,
36.15, 36.14, 36.02, 36.02, 36.02), THB.LAST = c(34.558,
34.601, 34.565, 34.565, 34.565, 34.565, 34.618, 34.64,
34.67, 34.635, 34.635, 34.635, 34.605, 34.7, 34.575,
34.61, 34.81, 34.81, 34.81, 34.76, 34.751, 34.965, 34.974,
34.822, 34.822, 34.822, 34.927, 34.94, 34.75, 34.77,
34.83, 34.83, 34.83, 34.868, 34.97, 35.01, 35.05, 34.93,
34.93, 34.93, 34.995, 34.989, 35.01, 35.005, 34.94, 34.94,
34.94, 35.03, 35.16, 35.138, 35.11, 35.25, 35.25, 35.25,
35.173, 35.214, 35.134, 35.048, 35.086, 35.086, 35.086,
35.138, 35.23, 35.29, 35.35, 35.339, 35.339, 35.339,
35.173, 35.24, 35.173, 35.21, 35.235, 35.235, 35.235,
35.24, 35.25, 35.3, 35.18, 35.26, 35.26, 35.26, 35.21,
35.21, 35.23, 35.28, 35.629, 35.629, 35.629, 35.61, 35.67,
35.705, 35.75, 35.658, 35.658, 35.658, 35.6, 35.71, 35.73,
35.66, 35.679, 35.679, 35.679, 35.71, 35.6, 35.49, 35.37,
35.43, 35.43, 35.43, 35.32, 35.27, 35.236, 35.13, 35.149,
35.149, 35.149, 35.179, 35.184, 34.92, 34.841, 34.92,
34.92, 34.92, 35.02, 35.15, 35.16, 35.11, 35.04, 35.04,
35.04, 35.01, 34.86, 34.91, 35.03, 35.065, 35.065, 35.065,
35.12, 35.036, 35.02, 35.07, 35.12, 35.12, 35.12, 35.205,
35.256, 35.32, 35.263, 35.105, 35.105, 35.105, 35.185,
35.235, 35.426, 35.36, 35.27, 35.27, 35.27, 35.35, 35.118,
34.91, 34.89, 34.85, 34.85, 34.85, 34.78, 35.02, 35.132,
35.08, 35.16, 35.16, 35.16, 35.25, 35.32, 35.425, 35.42,
35.403, 35.403, 35.403, 35.51, 35.57, 35.625, 35.64,
35.64, 35.64, 35.64, 35.68, 35.7, 35.74, 35.755, 35.745,
35.745, 35.745, 35.548, 35.61, 35.61, 35.65, 35.58, 35.58,
35.58, 35.245, 35.36, 35.489, 35.51, 35.497, 35.497,
35.497, 35.56, 35.841, 35.76, 35.605, 35.73, 35.73, 35.73,
35.825, 35.79, 35.908, 36.021, 36.037, 36.037, 36.037,
36.263, 36.3, 36.27, 36.32, 36.366, 36.366, 36.366, 36.313,
36.25, 36.33, 36.28, 36.307, 36.307, 36.307, 36.285,
36.22, 36.15, 36.14, 36.02, 36.02, 36.02)), .Names = c("Date",
"THB.OPEN", "THB.HIGH", "THB.LOW", "THB.CLOSE", "THB.LAST"
), row.names = c(NA, -243L), class = "data.frame"))

Related

R - Data Frame Forward and Backward Fill

I have a data frame and am trying to fill the missing values with the previous and next values in the data frame. I used the following code, but it did not fill and returns missing values still. I tried 2 different variations, but both do not work. Could someone please let me know what I am doing wrong? Thanks!
Data frame: 'oil.csv'
date dcoilwtico
1/1/13
1/2/13 93.14
1/3/13 92.97
1/4/13 93.12
1/7/13 93.2
1/8/13 93.21
1/9/13 93.08
1/10/13 93.81
1/11/13 93.6
1/14/13 94.27
1/15/13 93.26
1/16/13 94.28
1/17/13 95.49
1/18/13 95.61
1/21/13
1/22/13 96.09
dput(oil_df):
structure(list(date = c("2013-01-01", "2013-01-02", "2013-01-03",
"2013-01-04", "2013-01-07", "2013-01-08", "2013-01-09", "2013-01-10",
"2013-01-11", "2013-01-14", "2013-01-15", "2013-01-16", "2013-01-17",
"2013-01-18", "2013-01-21", "2013-01-22", "2013-01-23", "2013-01-24",
"2013-01-25", "2013-01-28", "2013-01-29", "2013-01-30", "2013-01-31",
"2013-02-01", "2013-02-04", "2013-02-05", "2013-02-06", "2013-02-07",
"2013-02-08", "2013-02-11", "2013-02-12", "2013-02-13", "2013-02-14",
"2013-02-15", "2013-02-18", "2013-02-19", "2013-02-20", "2013-02-21",
"2013-02-22", "2013-02-25", "2013-02-26", "2013-02-27", "2013-02-28",
"2013-03-01", "2013-03-04", "2013-03-05", "2013-03-06", "2013-03-07",
"2013-03-08", "2013-03-11", "2013-03-12", "2013-03-13", "2013-03-14",
"2013-03-15", "2013-03-18", "2013-03-19", "2013-03-20", "2013-03-21",
"2013-03-22", "2013-03-25", "2013-03-26", "2013-03-27", "2013-03-28",
"2013-03-29", "2013-04-01", "2013-04-02", "2013-04-03", "2013-04-04",
"2013-04-05", "2013-04-08", "2013-04-09", "2013-04-10", "2013-04-11",
"2013-04-12", "2013-04-15", "2013-04-16", "2013-04-17", "2013-04-18",
"2013-04-19", "2013-04-22", "2013-04-23", "2013-04-24", "2013-04-25",
"2013-04-26", "2013-04-29", "2013-04-30", "2013-05-01", "2013-05-02",
"2013-05-03", "2013-05-06", "2013-05-07", "2013-05-08", "2013-05-09",
"2013-05-10", "2013-05-13", "2013-05-14", "2013-05-15", "2013-05-16",
"2013-05-17", "2013-05-20", "2013-05-21", "2013-05-22", "2013-05-23",
"2013-05-24", "2013-05-27", "2013-05-28", "2013-05-29", "2013-05-30",
"2013-05-31", "2013-06-03", "2013-06-04", "2013-06-05", "2013-06-06",
"2013-06-07", "2013-06-10", "2013-06-11", "2013-06-12", "2013-06-13",
"2013-06-14", "2013-06-17", "2013-06-18", "2013-06-19", "2013-06-20",
"2013-06-21", "2013-06-24", "2013-06-25", "2013-06-26", "2013-06-27",
"2013-06-28", "2013-07-01", "2013-07-02", "2013-07-03", "2013-07-04",
"2013-07-05", "2013-07-08", "2013-07-09", "2013-07-10", "2013-07-11",
"2013-07-12", "2013-07-15", "2013-07-16", "2013-07-17", "2013-07-18",
"2013-07-19", "2013-07-22", "2013-07-23", "2013-07-24", "2013-07-25",
"2013-07-26", "2013-07-29", "2013-07-30", "2013-07-31", "2013-08-01",
"2013-08-02", "2013-08-05", "2013-08-06", "2013-08-07", "2013-08-08",
"2013-08-09", "2013-08-12", "2013-08-13", "2013-08-14", "2013-08-15",
"2013-08-16", "2013-08-19", "2013-08-20", "2013-08-21", "2013-08-22",
"2013-08-23", "2013-08-26", "2013-08-27", "2013-08-28", "2013-08-29",
"2013-08-30", "2013-09-02", "2013-09-03", "2013-09-04", "2013-09-05",
"2013-09-06", "2013-09-09", "2013-09-10", "2013-09-11", "2013-09-12",
"2013-09-13", "2013-09-16", "2013-09-17", "2013-09-18", "2013-09-19",
"2013-09-20", "2013-09-23", "2013-09-24", "2013-09-25", "2013-09-26",
"2013-09-27", "2013-09-30", "2013-10-01", "2013-10-02", "2013-10-03",
"2013-10-04", "2013-10-07", "2013-10-08", "2013-10-09", "2013-10-10",
"2013-10-11", "2013-10-14", "2013-10-15", "2013-10-16", "2013-10-17",
"2013-10-18", "2013-10-21", "2013-10-22", "2013-10-23", "2013-10-24",
"2013-10-25", "2013-10-28", "2013-10-29", "2013-10-30", "2013-10-31",
"2013-11-01", "2013-11-04", "2013-11-05", "2013-11-06", "2013-11-07",
"2013-11-08", "2013-11-11", "2013-11-12", "2013-11-13", "2013-11-14",
"2013-11-15", "2013-11-18", "2013-11-19", "2013-11-20", "2013-11-21",
"2013-11-22", "2013-11-25", "2013-11-26", "2013-11-27", "2013-11-28",
"2013-11-29", "2013-12-02", "2013-12-03", "2013-12-04", "2013-12-05",
"2013-12-06", "2013-12-09", "2013-12-10", "2013-12-11", "2013-12-12",
"2013-12-13", "2013-12-16", "2013-12-17", "2013-12-18", "2013-12-19",
"2013-12-20", "2013-12-23", "2013-12-24", "2013-12-25", "2013-12-26",
"2013-12-27", "2013-12-30", "2013-12-31", "2014-01-01", "2014-01-02",
"2014-01-03", "2014-01-06", "2014-01-07", "2014-01-08", "2014-01-09",
"2014-01-10", "2014-01-13", "2014-01-14", "2014-01-15", "2014-01-16",
"2014-01-17", "2014-01-20", "2014-01-21", "2014-01-22", "2014-01-23",
"2014-01-24", "2014-01-27", "2014-01-28", "2014-01-29", "2014-01-30",
"2014-01-31", "2014-02-03", "2014-02-04", "2014-02-05", "2014-02-06",
"2014-02-07", "2014-02-10", "2014-02-11", "2014-02-12", "2014-02-13",
"2014-02-14", "2014-02-17", "2014-02-18", "2014-02-19", "2014-02-20",
"2014-02-21", "2014-02-24", "2014-02-25", "2014-02-26", "2014-02-27",
"2014-02-28", "2014-03-03", "2014-03-04", "2014-03-05", "2014-03-06",
"2014-03-07", "2014-03-10", "2014-03-11", "2014-03-12", "2014-03-13",
"2014-03-14", "2014-03-17", "2014-03-18", "2014-03-19", "2014-03-20",
"2014-03-21", "2014-03-24", "2014-03-25", "2014-03-26", "2014-03-27",
"2014-03-28", "2014-03-31", "2014-04-01", "2014-04-02", "2014-04-03",
"2014-04-04", "2014-04-07", "2014-04-08", "2014-04-09", "2014-04-10",
"2014-04-11", "2014-04-14", "2014-04-15", "2014-04-16", "2014-04-17",
"2014-04-18", "2014-04-21", "2014-04-22", "2014-04-23", "2014-04-24",
"2014-04-25", "2014-04-28", "2014-04-29", "2014-04-30", "2014-05-01",
"2014-05-02", "2014-05-05", "2014-05-06", "2014-05-07", "2014-05-08",
"2014-05-09", "2014-05-12", "2014-05-13", "2014-05-14", "2014-05-15",
"2014-05-16", "2014-05-19", "2014-05-20", "2014-05-21", "2014-05-22",
"2014-05-23", "2014-05-26", "2014-05-27", "2014-05-28", "2014-05-29",
"2014-05-30", "2014-06-02", "2014-06-03", "2014-06-04", "2014-06-05",
"2014-06-06", "2014-06-09", "2014-06-10", "2014-06-11", "2014-06-12",
"2014-06-13", "2014-06-16", "2014-06-17", "2014-06-18", "2014-06-19",
"2014-06-20", "2014-06-23", "2014-06-24", "2014-06-25", "2014-06-26",
"2014-06-27", "2014-06-30", "2014-07-01", "2014-07-02", "2014-07-03",
"2014-07-04", "2014-07-07", "2014-07-08", "2014-07-09", "2014-07-10",
"2014-07-11", "2014-07-14", "2014-07-15", "2014-07-16", "2014-07-17",
"2014-07-18", "2014-07-21", "2014-07-22", "2014-07-23", "2014-07-24",
"2014-07-25", "2014-07-28", "2014-07-29", "2014-07-30", "2014-07-31",
"2014-08-01", "2014-08-04", "2014-08-05", "2014-08-06", "2014-08-07",
"2014-08-08", "2014-08-11", "2014-08-12", "2014-08-13", "2014-08-14",
"2014-08-15", "2014-08-18", "2014-08-19", "2014-08-20", "2014-08-21",
"2014-08-22", "2014-08-25", "2014-08-26", "2014-08-27", "2014-08-28",
"2014-08-29", "2014-09-01", "2014-09-02", "2014-09-03", "2014-09-04",
"2014-09-05", "2014-09-08", "2014-09-09", "2014-09-10", "2014-09-11",
"2014-09-12", "2014-09-15", "2014-09-16", "2014-09-17", "2014-09-18",
"2014-09-19", "2014-09-22", "2014-09-23", "2014-09-24", "2014-09-25",
"2014-09-26", "2014-09-29", "2014-09-30", "2014-10-01", "2014-10-02",
"2014-10-03", "2014-10-06", "2014-10-07", "2014-10-08", "2014-10-09",
"2014-10-10", "2014-10-13", "2014-10-14", "2014-10-15", "2014-10-16",
"2014-10-17", "2014-10-20", "2014-10-21", "2014-10-22", "2014-10-23",
"2014-10-24", "2014-10-27", "2014-10-28", "2014-10-29", "2014-10-30",
"2014-10-31", "2014-11-03", "2014-11-04", "2014-11-05", "2014-11-06",
"2014-11-07", "2014-11-10", "2014-11-11", "2014-11-12", "2014-11-13",
"2014-11-14", "2014-11-17", "2014-11-18", "2014-11-19", "2014-11-20",
"2014-11-21", "2014-11-24", "2014-11-25", "2014-11-26", "2014-11-27",
"2014-11-28", "2014-12-01", "2014-12-02", "2014-12-03", "2014-12-04",
"2014-12-05", "2014-12-08", "2014-12-09", "2014-12-10", "2014-12-11",
"2014-12-12", "2014-12-15", "2014-12-16", "2014-12-17", "2014-12-18",
"2014-12-19", "2014-12-22", "2014-12-23", "2014-12-24", "2014-12-25",
"2014-12-26", "2014-12-29", "2014-12-30", "2014-12-31", "2015-01-01",
"2015-01-02", "2015-01-05", "2015-01-06", "2015-01-07", "2015-01-08",
"2015-01-09", "2015-01-12", "2015-01-13", "2015-01-14", "2015-01-15",
"2015-01-16", "2015-01-19", "2015-01-20", "2015-01-21", "2015-01-22",
"2015-01-23", "2015-01-26", "2015-01-27", "2015-01-28", "2015-01-29",
"2015-01-30", "2015-02-02", "2015-02-03", "2015-02-04", "2015-02-05",
"2015-02-06", "2015-02-09", "2015-02-10", "2015-02-11", "2015-02-12",
"2015-02-13", "2015-02-16", "2015-02-17", "2015-02-18", "2015-02-19",
"2015-02-20", "2015-02-23", "2015-02-24", "2015-02-25", "2015-02-26",
"2015-02-27", "2015-03-02", "2015-03-03", "2015-03-04", "2015-03-05",
"2015-03-06", "2015-03-09", "2015-03-10", "2015-03-11", "2015-03-12",
"2015-03-13", "2015-03-16", "2015-03-17", "2015-03-18", "2015-03-19",
"2015-03-20", "2015-03-23", "2015-03-24", "2015-03-25", "2015-03-26",
"2015-03-27", "2015-03-30", "2015-03-31", "2015-04-01", "2015-04-02",
"2015-04-03", "2015-04-06", "2015-04-07", "2015-04-08", "2015-04-09",
"2015-04-10", "2015-04-13", "2015-04-14", "2015-04-15", "2015-04-16",
"2015-04-17", "2015-04-20", "2015-04-21", "2015-04-22", "2015-04-23",
"2015-04-24", "2015-04-27", "2015-04-28", "2015-04-29", "2015-04-30",
"2015-05-01", "2015-05-04", "2015-05-05", "2015-05-06", "2015-05-07",
"2015-05-08", "2015-05-11", "2015-05-12", "2015-05-13", "2015-05-14",
"2015-05-15", "2015-05-18", "2015-05-19", "2015-05-20", "2015-05-21",
"2015-05-22", "2015-05-25", "2015-05-26", "2015-05-27", "2015-05-28",
"2015-05-29", "2015-06-01", "2015-06-02", "2015-06-03", "2015-06-04",
"2015-06-05", "2015-06-08", "2015-06-09", "2015-06-10", "2015-06-11",
"2015-06-12", "2015-06-15", "2015-06-16", "2015-06-17", "2015-06-18",
"2015-06-19", "2015-06-22", "2015-06-23", "2015-06-24", "2015-06-25",
"2015-06-26", "2015-06-29", "2015-06-30", "2015-07-01", "2015-07-02",
"2015-07-03", "2015-07-06", "2015-07-07", "2015-07-08", "2015-07-09",
"2015-07-10", "2015-07-13", "2015-07-14", "2015-07-15", "2015-07-16",
"2015-07-17", "2015-07-20", "2015-07-21", "2015-07-22", "2015-07-23",
"2015-07-24", "2015-07-27", "2015-07-28", "2015-07-29", "2015-07-30",
"2015-07-31", "2015-08-03", "2015-08-04", "2015-08-05", "2015-08-06",
"2015-08-07", "2015-08-10", "2015-08-11", "2015-08-12", "2015-08-13",
"2015-08-14", "2015-08-17", "2015-08-18", "2015-08-19", "2015-08-20",
"2015-08-21", "2015-08-24", "2015-08-25", "2015-08-26", "2015-08-27",
"2015-08-28", "2015-08-31", "2015-09-01", "2015-09-02", "2015-09-03",
"2015-09-04", "2015-09-07", "2015-09-08", "2015-09-09", "2015-09-10",
"2015-09-11", "2015-09-14", "2015-09-15", "2015-09-16", "2015-09-17",
"2015-09-18", "2015-09-21", "2015-09-22", "2015-09-23", "2015-09-24",
"2015-09-25", "2015-09-28", "2015-09-29", "2015-09-30", "2015-10-01",
"2015-10-02", "2015-10-05", "2015-10-06", "2015-10-07", "2015-10-08",
"2015-10-09", "2015-10-12", "2015-10-13", "2015-10-14", "2015-10-15",
"2015-10-16", "2015-10-19", "2015-10-20", "2015-10-21", "2015-10-22",
"2015-10-23", "2015-10-26", "2015-10-27", "2015-10-28", "2015-10-29",
"2015-10-30", "2015-11-02", "2015-11-03", "2015-11-04", "2015-11-05",
"2015-11-06", "2015-11-09", "2015-11-10", "2015-11-11", "2015-11-12",
"2015-11-13", "2015-11-16", "2015-11-17", "2015-11-18", "2015-11-19",
"2015-11-20", "2015-11-23", "2015-11-24", "2015-11-25", "2015-11-26",
"2015-11-27", "2015-11-30", "2015-12-01", "2015-12-02", "2015-12-03",
"2015-12-04", "2015-12-07", "2015-12-08", "2015-12-09", "2015-12-10",
"2015-12-11", "2015-12-14", "2015-12-15", "2015-12-16", "2015-12-17",
"2015-12-18", "2015-12-21", "2015-12-22", "2015-12-23", "2015-12-24",
"2015-12-25", "2015-12-28", "2015-12-29", "2015-12-30", "2015-12-31",
"2016-01-01", "2016-01-04", "2016-01-05", "2016-01-06", "2016-01-07",
"2016-01-08", "2016-01-11", "2016-01-12", "2016-01-13", "2016-01-14",
"2016-01-15", "2016-01-18", "2016-01-19", "2016-01-20", "2016-01-21",
"2016-01-22", "2016-01-25", "2016-01-26", "2016-01-27", "2016-01-28",
"2016-01-29", "2016-02-01", "2016-02-02", "2016-02-03", "2016-02-04",
"2016-02-05", "2016-02-08", "2016-02-09", "2016-02-10", "2016-02-11",
"2016-02-12", "2016-02-15", "2016-02-16", "2016-02-17", "2016-02-18",
"2016-02-19", "2016-02-22", "2016-02-23", "2016-02-24", "2016-02-25",
"2016-02-26", "2016-02-29", "2016-03-01", "2016-03-02", "2016-03-03",
"2016-03-04", "2016-03-07", "2016-03-08", "2016-03-09", "2016-03-10",
"2016-03-11", "2016-03-14", "2016-03-15", "2016-03-16", "2016-03-17",
"2016-03-18", "2016-03-21", "2016-03-22", "2016-03-23", "2016-03-24",
"2016-03-25", "2016-03-28", "2016-03-29", "2016-03-30", "2016-03-31",
"2016-04-01", "2016-04-04", "2016-04-05", "2016-04-06", "2016-04-07",
"2016-04-08", "2016-04-11", "2016-04-12", "2016-04-13", "2016-04-14",
"2016-04-15", "2016-04-18", "2016-04-19", "2016-04-20", "2016-04-21",
"2016-04-22", "2016-04-25", "2016-04-26", "2016-04-27", "2016-04-28",
"2016-04-29", "2016-05-02", "2016-05-03", "2016-05-04", "2016-05-05",
"2016-05-06", "2016-05-09", "2016-05-10", "2016-05-11", "2016-05-12",
"2016-05-13", "2016-05-16", "2016-05-17", "2016-05-18", "2016-05-19",
"2016-05-20", "2016-05-23", "2016-05-24", "2016-05-25", "2016-05-26",
"2016-05-27", "2016-05-30", "2016-05-31", "2016-06-01", "2016-06-02",
"2016-06-03", "2016-06-06", "2016-06-07", "2016-06-08", "2016-06-09",
"2016-06-10", "2016-06-13", "2016-06-14", "2016-06-15", "2016-06-16",
"2016-06-17", "2016-06-20", "2016-06-21", "2016-06-22", "2016-06-23",
"2016-06-24", "2016-06-27", "2016-06-28", "2016-06-29", "2016-06-30",
"2016-07-01", "2016-07-04", "2016-07-05", "2016-07-06", "2016-07-07",
"2016-07-08", "2016-07-11", "2016-07-12", "2016-07-13", "2016-07-14",
"2016-07-15", "2016-07-18", "2016-07-19", "2016-07-20", "2016-07-21",
"2016-07-22", "2016-07-25", "2016-07-26", "2016-07-27", "2016-07-28",
"2016-07-29", "2016-08-01", "2016-08-02", "2016-08-03", "2016-08-04",
"2016-08-05", "2016-08-08", "2016-08-09", "2016-08-10", "2016-08-11",
"2016-08-12", "2016-08-15", "2016-08-16", "2016-08-17", "2016-08-18",
"2016-08-19", "2016-08-22", "2016-08-23", "2016-08-24", "2016-08-25",
"2016-08-26", "2016-08-29", "2016-08-30", "2016-08-31", "2016-09-01",
"2016-09-02", "2016-09-05", "2016-09-06", "2016-09-07", "2016-09-08",
"2016-09-09", "2016-09-12", "2016-09-13", "2016-09-14", "2016-09-15",
"2016-09-16", "2016-09-19", "2016-09-20", "2016-09-21", "2016-09-22",
"2016-09-23", "2016-09-26", "2016-09-27", "2016-09-28", "2016-09-29",
"2016-09-30", "2016-10-03", "2016-10-04", "2016-10-05", "2016-10-06",
"2016-10-07", "2016-10-10", "2016-10-11", "2016-10-12", "2016-10-13",
"2016-10-14", "2016-10-17", "2016-10-18", "2016-10-19", "2016-10-20",
"2016-10-21", "2016-10-24", "2016-10-25", "2016-10-26", "2016-10-27",
"2016-10-28", "2016-10-31", "2016-11-01", "2016-11-02", "2016-11-03",
"2016-11-04", "2016-11-07", "2016-11-08", "2016-11-09", "2016-11-10",
"2016-11-11", "2016-11-14", "2016-11-15", "2016-11-16", "2016-11-17",
"2016-11-18", "2016-11-21", "2016-11-22", "2016-11-23", "2016-11-24",
"2016-11-25", "2016-11-28", "2016-11-29", "2016-11-30", "2016-12-01",
"2016-12-02", "2016-12-05", "2016-12-06", "2016-12-07", "2016-12-08",
"2016-12-09", "2016-12-12", "2016-12-13", "2016-12-14", "2016-12-15",
"2016-12-16", "2016-12-19", "2016-12-20", "2016-12-21", "2016-12-22",
"2016-12-23", "2016-12-26", "2016-12-27", "2016-12-28", "2016-12-29",
"2016-12-30", "2017-01-02", "2017-01-03", "2017-01-04", "2017-01-05",
"2017-01-06", "2017-01-09", "2017-01-10", "2017-01-11", "2017-01-12",
"2017-01-13", "2017-01-16", "2017-01-17", "2017-01-18", "2017-01-19",
"2017-01-20", "2017-01-23", "2017-01-24", "2017-01-25", "2017-01-26",
"2017-01-27", "2017-01-30", "2017-01-31", "2017-02-01", "2017-02-02",
"2017-02-03", "2017-02-06", "2017-02-07", "2017-02-08", "2017-02-09",
"2017-02-10", "2017-02-13", "2017-02-14", "2017-02-15", "2017-02-16",
"2017-02-17", "2017-02-20", "2017-02-21", "2017-02-22", "2017-02-23",
"2017-02-24", "2017-02-27", "2017-02-28", "2017-03-01", "2017-03-02",
"2017-03-03", "2017-03-06", "2017-03-07", "2017-03-08", "2017-03-09",
"2017-03-10", "2017-03-13", "2017-03-14", "2017-03-15", "2017-03-16",
"2017-03-17", "2017-03-20", "2017-03-21", "2017-03-22", "2017-03-23",
"2017-03-24", "2017-03-27", "2017-03-28", "2017-03-29", "2017-03-30",
"2017-03-31", "2017-04-03", "2017-04-04", "2017-04-05", "2017-04-06",
"2017-04-07", "2017-04-10", "2017-04-11", "2017-04-12", "2017-04-13",
"2017-04-14", "2017-04-17", "2017-04-18", "2017-04-19", "2017-04-20",
"2017-04-21", "2017-04-24", "2017-04-25", "2017-04-26", "2017-04-27",
"2017-04-28", "2017-05-01", "2017-05-02", "2017-05-03", "2017-05-04",
"2017-05-05", "2017-05-08", "2017-05-09", "2017-05-10", "2017-05-11",
"2017-05-12", "2017-05-15", "2017-05-16", "2017-05-17", "2017-05-18",
"2017-05-19", "2017-05-22", "2017-05-23", "2017-05-24", "2017-05-25",
"2017-05-26", "2017-05-29", "2017-05-30", "2017-05-31", "2017-06-01",
"2017-06-02", "2017-06-05", "2017-06-06", "2017-06-07", "2017-06-08",
"2017-06-09", "2017-06-12", "2017-06-13", "2017-06-14", "2017-06-15",
"2017-06-16", "2017-06-19", "2017-06-20", "2017-06-21", "2017-06-22",
"2017-06-23", "2017-06-26", "2017-06-27", "2017-06-28", "2017-06-29",
"2017-06-30", "2017-07-03", "2017-07-04", "2017-07-05", "2017-07-06",
"2017-07-07", "2017-07-10", "2017-07-11", "2017-07-12", "2017-07-13",
"2017-07-14", "2017-07-17", "2017-07-18", "2017-07-19", "2017-07-20",
"2017-07-21", "2017-07-24", "2017-07-25", "2017-07-26", "2017-07-27",
"2017-07-28", "2017-07-31", "2017-08-01", "2017-08-02", "2017-08-03",
"2017-08-04", "2017-08-07", "2017-08-08", "2017-08-09", "2017-08-10",
"2017-08-11", "2017-08-14", "2017-08-15", "2017-08-16", "2017-08-17",
"2017-08-18", "2017-08-21", "2017-08-22", "2017-08-23", "2017-08-24",
"2017-08-25", "2017-08-28", "2017-08-29", "2017-08-30", "2017-08-31"
), dcoilwtico = c(NA, 93.14, 92.97, 93.12, 93.2, 93.21, 93.08,
93.81, 93.6, 94.27, 93.26, 94.28, 95.49, 95.61, NA, 96.09, 95.06,
95.35, 95.15, 95.95, 97.62, 97.98, 97.65, 97.46, 96.21, 96.68,
96.44, 95.84, 95.71, 97.01, 97.48, 97.03, 97.3, 95.95, NA, 96.69,
94.92, 92.79, 93.12, 92.74, 92.63, 92.84, 92.03, 90.71, 90.13,
90.88, 90.47, 91.53, 92.01, 92.07, 92.44, 92.47, 93.03, 93.49,
93.71, 92.44, 93.21, 92.46, 93.41, 94.55, 95.99, 96.53, 97.24,
NA, 97.1, 97.23, 95.02, 93.26, 92.76, 93.36, 94.18, 94.59, 93.44,
91.23, 88.75, 88.73, 86.65, 87.83, 88.04, 88.81, 89.21, 91.07,
93.27, 92.63, 94.09, 93.22, 90.74, 93.7, 95.25, 95.8, 95.28,
96.24, 96.09, 95.81, 94.76, 93.96, 93.95, 94.85, 95.72, 96.29,
95.55, 93.98, 94.12, 93.84, NA, 94.65, 93.13, 93.57, 91.93, 93.41,
93.36, 93.66, 94.71, 96.11, 95.82, 95.5, 95.98, 96.66, 97.83,
97.86, 98.46, 98.24, 94.89, 93.81, 95.07, 95.25, 95.47, 97, 96.36,
97.94, 99.65, 101.92, NA, 103.09, 103.03, 103.46, 106.41, 104.77,
105.85, 106.2, 105.88, 106.39, 107.94, 108, 106.61, 107.13, 105.41,
105.47, 104.76, 104.61, 103.14, 105.1, 107.93, 106.94, 106.61,
105.32, 104.41, 103.45, 106.04, 106.19, 106.78, 106.89, 107.43,
107.58, 107.14, 104.9, 103.93, 104.93, 106.48, 105.88, 109.11,
110.17, 108.51, 107.98, NA, 108.67, 107.29, 108.5, 110.62, 109.62,
107.48, 107.65, 108.72, 108.31, 106.54, 105.36, 108.23, 106.26,
104.7, 103.62, 103.22, 102.68, 103.1, 102.86, 102.36, 102.09,
104.15, 103.29, 103.83, 103.07, 103.54, 101.63, 103.08, 102.17,
102.46, 101.15, 102.34, 100.72, 100.87, 99.28, 97.63, 96.9, 96.65,
97.4, 98.74, 98.29, 96.81, 96.29, 94.56, 94.58, 93.4, 94.74,
94.25, 94.56, 95.13, 93.12, 93.91, 93.76, 93.8, 93.03, 93.35,
93.34, 95.35, 94.53, 93.86, 93.41, 92.05, NA, 92.55, 93.61, 95.83,
96.97, 97.14, 97.48, 97.1, 98.32, 97.25, 97.21, 96.27, 97.18,
96.99, 97.59, 98.4, 99.11, 98.62, 98.87, NA, 99.18, 99.94, 98.9,
98.17, NA, 95.14, 93.66, 93.12, 93.31, 91.9, 91.36, 92.39, 91.45,
92.15, 93.78, 93.54, 93.96, NA, 94.51, 96.35, 97.23, 96.66, 95.82,
97.49, 97.34, 98.25, 97.55, 96.44, 97.24, 97.4, 97.84, 99.98,
100.12, 99.96, 100.38, 100.27, 100.31, NA, 102.54, 103.46, 103.2,
102.53, 103.17, 102.2, 102.93, 102.68, 102.88, 105.34, 103.64,
101.75, 101.82, 102.82, 101.39, 100.29, 98.29, 98.57, 99.23,
98.43, 100.08, 100.71, 99.68, 99.97, 100.05, 99.66, 100.61, 101.25,
101.73, 101.57, 99.69, 99.6, 100.29, 101.16, 100.43, 102.57,
103.55, 103.37, 103.68, 104.05, 103.7, 103.71, 104.33, NA, 104.35,
101.69, 101.47, 102.2, 100.85, 101.13, 101.56, 100.07, 99.69,
100.09, 99.74, 99.81, 101.06, 100.52, 100.32, 100.89, 102.01,
102.63, 101.74, 102.31, 102.95, 102.8, 104.31, 104.03, 105.01,
NA, 104.78, 103.37, 104.26, 103.4, 103.07, 103.34, 103.27, 103.17,
103.32, 105.09, 105.02, 105.04, 107.2, 107.49, 107.52, 106.95,
106.64, 107.08, 107.95, 106.83, 106.64, 107.04, 106.49, 106.46,
106.07, 106.06, 105.18, 104.76, NA, 104.19, 104.06, 102.93, 103.61,
101.48, 101.73, 100.56, 101.88, 103.84, 103.83, 105.34, 104.59,
103.81, 102.76, 105.23, 105.68, 104.91, 104.29, 98.23, 97.86,
98.26, 97.34, 96.93, 97.34, 97.61, 98.09, 97.36, 97.57, 95.54,
97.3, 96.44, 94.35, 96.4, 93.97, 93.61, 95.39, 95.78, 95.82,
96.44, 97.86, NA, 92.92, 95.5, 94.51, 93.32, 92.64, 92.73, 91.71,
92.89, 92.18, 92.86, 94.91, 94.33, 93.07, 92.43, 91.46, 91.55,
93.6, 93.59, 95.55, 94.53, 91.17, 90.74, 91.02, 89.76, 90.33,
88.89, 87.29, 85.76, 85.87, 85.73, 81.72, 81.82, 82.33, 82.8,
82.76, 83.25, 80.52, 82.81, 81.27, 81.26, 81.36, 82.25, 81.06,
80.53, 78.77, 77.15, 78.71, 77.87, 78.71, 77.43, 77.85, 77.16,
74.13, 75.91, 75.64, 74.55, 74.55, 75.63, 76.52, 75.74, 74.04,
73.7, NA, 65.94, 68.98, 66.99, 67.3, 66.73, 65.89, 63.13, 63.74,
60.99, 60.01, 57.81, 55.96, 55.97, 56.43, 54.18, 56.91, 55.25,
56.78, 55.7, NA, 54.59, 53.46, 54.14, 53.45, NA, 52.72, 50.05,
47.98, 48.69, 48.8, 48.35, 46.06, 45.92, 48.49, 46.37, 48.49,
NA, 46.79, 47.85, 45.93, 45.26, 44.8, 45.84, 44.08, 44.12, 47.79,
49.25, 53.04, 48.45, 50.48, 51.66, 52.99, 50.06, 48.8, 51.17,
52.66, NA, 53.56, 52.13, 51.12, 49.95, 49.56, 48.48, 50.25, 47.65,
49.84, 49.59, 50.43, 51.53, 50.76, 49.61, 49.95, 48.42, 48.06,
47.12, 44.88, 43.93, 43.39, 44.63, 44.02, 46, 47.4, 47.03, 48.75,
51.41, 48.83, 48.66, 47.72, 50.12, 49.13, NA, 52.08, 53.95, 50.44,
50.79, 51.63, 51.95, 53.3, 56.25, 56.69, 55.71, 56.37, 55.58,
56.17, 56.59, 55.98, 55.56, 57.05, 58.55, 59.62, 59.1, 58.92,
60.38, 60.93, 58.99, 59.41, 59.23, 60.72, 60.5, 59.89, 59.73,
59.44, 57.3, 58.96, 60.18, 58.88, NA, 57.29, 57.51, 57.69, 60.25,
60.24, 61.3, 59.67, 58, 59.11, 58.15, 60.15, 61.36, 60.74, 59.96,
59.53, 60.01, 59.89, 60.41, 59.62, 60.01, 61.05, 60.01, 59.59,
59.41, 58.34, 59.48, 56.94, 56.93, NA, 52.48, 52.33, 51.61, 52.76,
52.74, 52.19, 53.05, 51.4, 50.9, 50.88, 50.11, 50.59, 49.27,
48.11, 47.98, 47.17, 47.97, 48.77, 48.53, 47.11, 45.25, 45.75,
45.13, 44.69, 43.87, 44.94, 43.11, 43.22, 42.27, 42.45, 41.93,
42.58, 40.75, 41, 40.45, 38.22, 39.15, 38.5, 42.47, 45.29, 49.2,
45.38, 46.3, 46.75, 46.02, NA, 45.92, 44.13, 45.85, 44.75, 44.07,
44.58, 47.12, 46.93, 44.71, 46.67, 46.17, 44.53, 44.94, 45.55,
44.4, 45.24, 45.06, 44.75, 45.54, 46.28, 48.53, 47.86, 49.46,
49.67, 47.09, 46.7, 46.63, 46.38, 47.3, 45.91, 45.84, 45.22,
44.9, 43.91, 43.19, 43.21, 45.93, 46.02, 46.6, 46.12, 47.88,
46.32, 45.27, 44.32, 43.87, 44.23, 42.95, 41.74, 40.69, 41.68,
40.73, 40.75, 40.55, 39.39, 39.27, 40.89, 41.22, NA, 40.57, 40.43,
40.58, 39.93, 41.08, 40, 37.64, 37.46, 37.16, 36.76, 35.65, 36.31,
37.32, 35.55, 34.98, 34.72, 34.55, 36.12, 36.76, 37.62, NA, 36.36,
37.88, 36.59, 37.13, NA, 36.81, 35.97, 33.97, 33.29, 33.2, 31.42,
30.42, 30.42, 31.22, 29.45, NA, 28.47, 26.68, 29.55, 32.07, 30.31,
29.54, 32.32, 33.21, 33.66, 31.62, 29.9, 32.29, 31.63, 30.86,
29.71, 27.96, 27.54, 26.19, 29.32, NA, 29.05, 30.68, 30.77, 29.59,
31.37, 31.84, 30.35, 31.4, 31.65, 32.74, 34.39, 34.57, 34.56,
35.91, 37.9, 36.67, 37.62, 37.77, 38.51, 37.2, 36.32, 38.43,
40.17, 39.47, 39.91, 41.45, 38.28, 38.14, NA, 37.99, 36.91, 36.91,
36.94, 35.36, 34.3, 34.52, 37.74, 37.3, 39.74, 40.46, 42.12,
41.7, 41.45, 40.4, 39.74, 40.88, 42.72, 43.18, 42.76, 41.67,
42.52, 45.29, 46.03, 45.98, 44.75, 43.65, 43.77, 44.33, 44.58,
43.45, 44.68, 46.21, 46.64, 46.22, 47.72, 48.29, 48.12, 48.16,
47.67, 48.12, 48.04, 49.1, 49, 49.36, NA, 49.1, 49.07, 49.14,
48.69, 49.71, 50.37, 51.23, 50.52, 49.09, 48.89, 48.49, 47.92,
46.14, 48, 49.4, 48.95, 49.16, 49.34, 46.7, 45.8, 47.93, 49.85,
48.27, 49.02, NA, 46.73, 47.37, 45.22, 45.37, 44.73, 46.82, 44.87,
45.64, 45.93, 45.23, 44.64, 44.96, 43.96, 43.41, 42.4, 42.16,
41.9, 41.13, 41.54, 40.05, 39.5, 40.8, 41.92, 41.83, 43.06, 42.78,
41.75, 43.51, 44.47, 45.72, 46.57, 46.81, 48.2, 48.48, 46.8,
47.54, 46.29, 46.97, 47.64, 46.97, 46.32, 44.68, 43.17, 44.39,
NA, 44.85, 45.47, 47.63, 45.88, 46.28, 44.91, 43.62, 43.85, 43.04,
43.34, 43.85, 45.33, 46.1, 44.36, 45.6, 44.65, 47.07, 47.72,
47.72, 48.8, 48.67, 49.75, 50.44, 49.76, 49.76, 50.72, 50.14,
50.47, 50.35, 49.97, 50.3, 51.59, 50.31, 50.61, 50.18, 49.45,
48.75, 49.71, 48.72, 46.83, 46.66, 45.32, 44.66, 44.07, 44.88,
44.96, 45.2, 44.62, 43.39, 43.29, 45.86, 45.56, 45.37, 45.69,
47.48, 48.07, 46.72, NA, 46.72, 45.66, 45.29, 49.41, 51.08, 51.7,
51.72, 50.95, 49.85, 50.84, 51.51, 52.74, 52.99, 51.01, 50.9,
51.93, 52.13, 52.22, 51.44, 51.98, 52.01, NA, 52.82, 54.01, 53.8,
53.75, NA, 52.36, 53.26, 53.77, 53.98, 51.95, 50.82, 52.19, 53.01,
52.36, NA, 52.45, 51.12, 51.39, 52.33, 52.77, 52.38, 52.14, 53.24,
53.18, 52.63, 52.75, 53.9, 53.55, 53.81, 53.01, 52.19, 52.37,
52.99, 53.84, 52.96, 53.21, 53.11, 53.41, 53.41, NA, 54.02, 53.61,
54.48, 53.99, 54.04, 54, 53.82, 52.63, 53.33, 53.19, 52.68, 49.83,
48.75, 48.05, 47.95, 47.24, 48.34, 48.3, 48.34, 47.79, 47.02,
47.29, 47, 47.3, 47.02, 48.36, 49.47, 50.3, 50.54, 50.25, 50.99,
51.14, 51.69, 52.25, 53.06, 53.38, 53.12, 53.19, NA, 52.62, 52.46,
50.49, 50.26, 49.64, 48.9, 49.22, 49.22, 48.96, 49.31, 48.83,
47.65, 47.79, 45.55, 46.23, 46.46, 45.84, 47.28, 47.81, 47.83,
48.86, 48.64, 49.04, 49.36, 50.32, 50.81, 51.12, 50.99, 48.57,
49.58, NA, 49.63, 48.29, 48.32, 47.68, 47.4, 48.13, 45.8, 45.68,
45.82, 46.1, 46.41, 44.79, 44.47, 44.73, 44.24, 43.34, 42.48,
42.53, 42.86, 43.24, 44.25, 44.74, 44.88, 46.02, NA, NA, 45.11,
45.52, 44.25, 44.4, 45.06, 45.48, 46.06, 46.53, 46.02, 46.4,
47.1, 46.73, 45.78, 46.21, 47.77, 48.58, 49.05, 49.72, 50.21,
49.19, 49.6, 49.03, 49.57, 49.37, 49.07, 49.59, 48.54, 48.81,
47.59, 47.57, 46.8, 47.07, 48.59, 47.39, 47.65, 48.45, 47.24,
47.65, 46.4, 46.46, 45.96, 47.26)), class = "data.frame", row.names = c(NA,
-1218L))
Code:
# Tried both of these options, and both don't work
oil_df %>% fill(everything()) %>% fill(everything(), .direction = 'up')
na.locf(na.locf(oil_df), fromLast = TRUE)
# Confirm oil_df has no more missing values
sum(is.na(oil_df))
Output: Excepted 0
> na.locf(na.locf(oil_df), fromLast = TRUE)
>
> # Confirm oil_df has no more missing values
> sum(is.na(oil_df))
[1] 43
The problem with the code in the question is that it is calculating a result and then throwing it away and instead of checking the result it is checking the original data frame. Assign the result of the na.locf to a variable and then check that object. Also note that since there are no NA's on the end we can just use one na.locf if it is ok that the NA's get filled in with the next non-NA.
library(zoo)
oil_df2 <- na.locf(oil_df, fromLast = TRUE)
sum(is.na(oil_df2))
## [1] 0
You can use the downup parameter of fill() in the tidyr package :
Direction in which to fill missing values. Currently either "down" (the default), "up", "downup" (i.e. first down and then up) or "updown" (first up and then down)
df <- data.frame(
id = 1:10,
value = c(NA,100,runif(4,100,200),NA,runif(3,100,200))
)
id value
1 1 NA
2 2 100.0000
3 3 129.3819
4 4 137.7009
5 5 187.6759
6 6 155.0566
7 7 NA
8 8 125.9839
9 9 159.3502
10 10 129.0750
df <- df %>%
fill(value, .direction = "downup")
df
id value
1 1 100.0000
2 2 100.0000
3 3 129.3819
4 4 137.7009
5 5 187.6759
6 6 155.0566
7 7 155.0566
8 8 125.9839
9 9 159.3502
10 10 129.0750

R: Extract single month data from a monthly time-series

Question
I have a monthly time series (object axts in the code below) for the period Jan 1993 - Dec 2019 and I would like to create a time series that contains all the data for a single month, e.g. february.
Details
This is its structure:
str(axts)
An ‘xts’ object on Jan 1993/Dec 2019 containing:
Data: num [1:324, 1] -28.3 -22.8 -67.1 -122.5 -72.7 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr "SSH"
Indexed by objects of class: [yearmon] TZ: UTC
xts Attributes:
NULL
Here is its creation:
axts<-structure(c(-28.3, -22.8, -67.1, -122.5, -72.7, -102.6, 49.3, 107.2,
62.6, 98.8, 51.6, -12.8, -36.5, -22.6, -53.6, -16.3, -83.6,
-127.5, -40.2, -80.8, -71.4, -89.6, -78, -24.6, -41.8, -79.2,
-88.9, -111.3, -127.6, -97.6, -41.6, -6.3, -8, -15.8, -21.6,
1.5, 33.4, 71.5, 36, -18.8, 78.5, -20.4, 111.1, 93.5, 142.5,
110.4, 60, 78.6, 72.6, -5.2, -65.7, -102.1, -61, 109.8, 69.8,
67.7, 47.6, 64.7, 52.7, -20, -58, 41.7, 5.8, -3.1, 120.1, 180.3,
149.4, 213.7, 166.4, 78.5, 65.6, 12.1, -2.7, -46.1, -27.2,
72.8, 11.3, 46.4, 50.3, 40, 78.5, 154.8, 178.1, 99.9, 66.5,
-47.1, -76.7, -6.9, -23.6, 113.7, 37.6, 120.6, 136.9, 116.1,
79.6, 33.3, 66.8, -5.3, 8.3, 95, 81.7, 82.9, 118.6, 140, 139.8,
126.2, 157.6, 95.1, 95.7, 26.8, 116.6, 77.3, 106.7, -53.3, -104.4,
-88.1, -58.9, -17.8, 159.1, 179.8, 27.1, -88.5, -84.2, -34.3, 61,
102, 133.1, 162, 130, 124.8, 133.7, 109.6, 21.9, 123, 113.5, 102.4,
117.2, 24.9, 45.6, 71.2, 163.8, 118, 54.2, 87.4, 97.9, 127.2, 11.6,
-84.1, 15.1, 5.9, 71, 140.6, 47.4, 26.4, 36.2, 5.4, -5.4, -46.8, -25.3,
-79.4, -45.8, 40.1, -52.8, -95.5, -56.5, 175.6, 140.6, -10.5, -77.7, -26.8,
73.6, 13.4, 15.4, 128.1, 129.2, 50.6, 7.5, -27.6, 19.2, 61, 84.3, -31.2,
-19.1, 31.8, 22.4, -31, -93.9, -25.8, -4.1, 87.3, -12.8, -125.8, -58.1,
74.5, 41, -141.6, -142.1, -92.9, 25.6, 50.8, 139.3, 126.1, -10.4, 45.1,
92.2, 47.4, -1.6, -46.9, 69.4, -52.3, 18.2, 194.8, 157.6, 37.3, 28.3, -18,
-46.8, -95.8, -146, -172.4, -14.7, -33.4, -46.4, 5.9, 146.3, 124.5, 82.8,
-5.9, -124.7, -108.4, -66.3, -61.8, -62.6, 29.6, 38.5, 8.3, 158.4, 80.2, 10.5,
27.1, 21.2, 21.2, 121.8, 94.3, -86.3, -49.4, 178.4, 100.3, 68.6, 106.5, 72.1, 58.6,
-42.5, -74.6, -85.3, -100.1, -122.5, -125.7, -109.3, -100.6, -17, 2.8, -58, -32.4,
-63.2, 28.4, -99.8, -198.3, -103, 36.3, 47.5, 85.4, 124.9, 61.6, -150.2, -174.6,
-182.3, -69.3, -48.8, -10.3, 82.3, 13.9, -40, 64.1, 126.1, 15.5, 49.8, 12.3, -105,
-23.9, -51.7, -25.6, -140.1, -73.1, -66.1, -57, -20.1, -50.1, 25.3, -67.9, -47.8,
6.3, 13.2, 48.1, -50.8, 26.5, -58.4, -70.6, 81.2, 41.9, -32.6, 25.1, 118.7, 82.6,
62.6, 13.9, -149.5, 8, -32.8, 70.8, 96.9, 146.7, 106.2, -21.3),
.Dim = c(324L, 1L), index = structure(c(725846400, 728524800, 730944000, 733622400, 736214400,
738892800, 741484800, 744163200, 746841600, 749433600,
752112000, 754704000, 757382400, 760060800, 762480000,
765158400, 767750400, 770428800, 773020800, 775699200,
778377600, 780969600, 783648000, 786240000, 788918400, 791596800,
794016000, 796694400, 799286400, 801964800, 804556800, 807235200,
809913600, 812505600, 815184000, 817776000, 820454400, 823132800,
825638400, 828316800, 830908800, 833587200, 836179200, 838857600,
841536000, 844128000, 846806400, 849398400, 852076800, 854755200,
857174400, 859852800, 862444800, 865123200, 867715200, 870393600,
873072000, 875664000, 878342400, 880934400, 883612800, 886291200,
888710400, 891388800, 893980800, 896659200, 899251200, 901929600,
904608000, 907200000, 909878400, 912470400, 915148800, 917827200,
920246400, 922924800, 925516800, 928195200, 930787200, 933465600,
936144000, 938736000, 941414400, 944006400, 946684800, 949363200,
951868800, 954547200, 957139200, 959817600, 962409600, 965088000,
967766400, 970358400, 973036800, 975628800, 978307200, 980985600,
983404800, 986083200, 988675200, 991353600, 993945600, 996624000,
999302400, 1001894400, 1004572800, 1007164800, 1009843200, 1012521600,
1014940800, 1017619200, 1020211200, 1022889600, 1025481600, 1028160000,
1030838400, 1033430400, 1036108800, 1038700800, 1041379200, 1044057600,
1046476800, 1049155200, 1051747200, 1054425600, 1057017600, 1059696000,
1062374400, 1064966400, 1067644800, 1070236800, 1072915200, 1075593600,
1078099200, 1080777600, 1083369600, 1086048000, 1088640000, 1091318400,
1093996800, 1096588800, 1099267200, 1101859200, 1104537600, 1107216000,
1109635200, 1112313600, 1114905600, 1117584000, 1120176000, 1122854400,
1125532800, 1128124800, 1130803200, 1133395200, 1136073600, 1138752000,
1141171200, 1143849600, 1146441600, 1149120000, 1151712000, 1154390400,
1157068800, 1159660800, 1162339200, 1164931200, 1167609600, 1170288000,
1172707200, 1175385600, 1177977600, 1180656000, 1183248000, 1185926400,
1188604800, 1191196800, 1193875200, 1196467200, 1199145600, 1201824000,
1204329600, 1207008000, 1209600000, 1212278400, 1214870400, 1217548800,
1220227200, 1222819200, 1225497600, 1228089600, 1230768000, 1233446400,
1235865600, 1238544000, 1241136000, 1243814400, 1246406400, 1249084800,
1251763200, 1254355200, 1257033600, 1259625600, 1262304000, 1264982400,
1267401600, 1270080000, 1272672000, 1275350400, 1277942400, 1280620800,
1283299200, 1285891200, 1288569600, 1291161600, 1293840000, 1296518400,
1298937600, 1301616000, 1304208000, 1306886400, 1309478400, 1312156800,
1314835200, 1317427200, 1320105600, 1322697600, 1325376000, 1328054400,
1330560000, 1333238400, 1335830400, 1338508800, 1341100800, 1343779200,
1346457600, 1349049600, 1351728000, 1354320000, 1356998400, 1359676800,
1362096000, 1364774400, 1367366400, 1370044800, 1372636800, 1375315200,
1377993600, 1380585600, 1383264000, 1385856000, 1388534400, 1391212800,
1393632000, 1396310400, 1398902400, 1401580800, 1404172800, 1406851200,
1409529600, 1412121600, 1414800000, 1417392000, 1420070400, 1422748800,
1425168000, 1427846400, 1430438400, 1433116800, 1435708800, 1438387200,
1441065600, 1443657600, 1446336000, 1448928000, 1451606400, 1454284800,
1456790400, 1459468800, 1462060800, 1464739200, 1467331200, 1470009600,
1472688000, 1475280000, 1477958400, 1480550400, 1483228800, 1485907200,
1488326400, 1491004800, 1493596800, 1496275200, 1498867200, 1501545600,
1504224000, 1506816000, 1509494400, 1512086400, 1514764800, 1517443200,
1519862400, 1522540800, 1525132800, 1527811200, 1530403200, 1533081600,
1535760000, 1538352000, 1541030400, 1543622400, 1546300800, 1548979200,
1551398400, 1554076800, 1556668800, 1559347200, 1561939200, 1564617600,
1567296000, 1569888000, 1572566400, 1575158400),
tzone = "UTC", tclass = "yearmon", tformat = "%m/%Y"), class = c("xts", "zoo"), .Dimnames = list(NULL, "SSH"))
Because the index of axts is of yearmon class we can use cycle to get the month number so for February (2nd month of the year):
axts[cycle(axts) == 2]
giving:
SSH
02/1993 -22.8
02/1994 -22.6
02/1995 -79.2
02/1996 71.5
02/1997 -5.2
02/1998 41.7
## ...snip...
If the reason you want this is to create a plot for each month then we don't even need that as it can be done simply using monthplot which produces 12 side by side plots, one for each month.
monthplot(as.ts(axts), ylab = "SSH")
I edited your dput because there were some minor errors in it but should be good now.
I done some transformations of your data so that it is only taking the value from on specific month of each year; in this case, February.
#do some transformations first
axts_df<-as.data.frame(axts)
library(data.table)
library(lubridate)
axts_df<-setDT(axts_df, keep.rownames = T)[]
axts_df$MonthYear<-my(axts_df$rn)
axts_df$Month<-month(axts_df$MonthYear)
#for February only:-
library(dplyr)
axts_df_feb<-axts_df%>%
filter(Month==2)
#convert back into time series
axts_df_feb$rn<-NULL
axts_df_feb$Month<-NULL
axts_df_feb_ts<-ts(axts_df_feb$SSH)
plot(axts_df_feb_ts)
The plot below gives you the value for every February of each year.
However, there is a way to do this in ggplot2, you could do it like this:-
ggplot(axts_df_feb, aes(x=MonthYear,y=SSH))+geom_line()+ggtitle("Values for every February (1993-2019)")

R Scaling a vector between -1 and 1

I have a vector with 100 elements.
vec <- c(58.12, 51.97, 61.83, 53.46, 30.67, 38.8, 48.79, 56.82, 20.19,
53.1, 54.95, 46.45, 41.09, 51.76, 52.56, 44.63, 52.95, 30, 50.7,
56.33, 64.72, 39.99, 39.37, 33.82, 47.62, 51.28, 37.38, 50.55,
68.39, 53.88, 33.37, 29.69, 30.74, 47.51, 72.64, 47.88, 42.28,
62.71, 47.47, 71.45, 55.94, 39.5, 32.97, 28.81, 56.59, 49.79,
43.49, 41.97, 43.61, 30.09, 50.18, 63.88, 57.77, 41.57, 27.52,
38.47, 46.13, 41.85, 39.14, 46.38, 47.73, 61.51, 66.73, 56.28,
59.89, 47.38, 27.27, 17.41, 36.8, 27.21, 43.13, 43.68, 29.33,
53.76, 74.69, 29.56, 63.41, 31.61, 56.32, 49.68, 48.65, 46.81,
51.23, 65.23, 54.79, 84.64, 63.55, 32.4, 47.93, 68.13, 33.05,
30.21, 40.62, 48.28, 38.69, 31.72, 52.01, 64.17, 53.12, 35.03)
I want to scale this vector vec so that all the numbers between 0 to 50 are scaled from -1 to 0 and all number between 50 to 100 are scaled from 0 to 1.
I have written the following code to do this -
newvec = ifelse(vec < 50, -(vec/min(vec, na.rm = T)), vec/max(vec, na.rm = T))
plot(vec, newvec)
The output looks like (see the black circles) -
For the numbers above 50, scaling is fine, however, for the numbers below 50, the scaling is working in reverse order and is incorrect (as showing in the graph).
I have drawn a red line in this graph showing the correct scaling.
Can someone show, what I am doing wrong?
Thanks.
looks like a perfect linear equation!
m <- lm( y~x, data=data.frame( x=c(0,50,100), y=c(-1,0,1) ) )
coef(m)
gives:
(Intercept) x
-1.00 0.02
So multiply by 0.02 and subtract 1
You could do it by first rescaling it to 0-1 to then multiply it by two and subtracting one:
vec <- c(58.12, 51.97, 61.83, 53.46, 30.67, 38.8, 48.79, 56.82, 20.19,
53.1, 54.95, 46.45, 41.09, 51.76, 52.56, 44.63, 52.95, 30, 50.7,
56.33, 64.72, 39.99, 39.37, 33.82, 47.62, 51.28, 37.38, 50.55,
68.39, 53.88, 33.37, 29.69, 30.74, 47.51, 72.64, 47.88, 42.28,
62.71, 47.47, 71.45, 55.94, 39.5, 32.97, 28.81, 56.59, 49.79,
43.49, 41.97, 43.61, 30.09, 50.18, 63.88, 57.77, 41.57, 27.52,
38.47, 46.13, 41.85, 39.14, 46.38, 47.73, 61.51, 66.73, 56.28,
59.89, 47.38, 27.27, 17.41, 36.8, 27.21, 43.13, 43.68, 29.33,
53.76, 74.69, 29.56, 63.41, 31.61, 56.32, 49.68, 48.65, 46.81,
51.23, 65.23, 54.79, 84.64, 63.55, 32.4, 47.93, 68.13, 33.05,
30.21, 40.62, 48.28, 38.69, 31.72, 52.01, 64.17, 53.12, 35.03)
rescale_minMax <- function(x){
1 - (x - max(x)) / (min(x) - max(x))
}
newvec = rescale_minMax(vec) * 2 - 1
plot(vec, newvec)
Created on 2021-03-12 by the reprex package (v0.3.0)

How do I store values after for() loop function?

I've been struggling for a few days with this problem, so help would be much appreciated. I have a line in a function that goes like this:
sig <- which(!ma.sig[1,]==0)&which(!pricebreak[1,]==0) ## Retrieves signals
sig <- which(sig)
for (i in 1:length(sig))
cursig[i] <- cur[i]
}
Basically what I'm doing is calculating signals, and if these signals are 0 or 1 I want R to save the corresponding variables. So for example, here's what the signal table might look like:
>ma.sig(MergedData)
Eur JPY GBP CHF AUD CAD NZD SEK NOK
1 0 1 0 1 1 0 0 0
>price.break(MergedData)
Eur JPY GBP CHF AUD CAD NZD SEK NOK
1 0 1 0 1 1 0 1 1
And so on for 29 variables. And here's the original currency, cur, vector:
> cur
[1] "EUR" "JPY" "GBP" "CHF" "AUD" "CAD" "NZD" "SEK" "NOK" "CZK" "HUF" "ILS" "PLN" "RUB" "TRY"
[16] "ZAR" "BRL" "CLP" "COP" "MXN" "PEN" "CNY" "IDR" "INR" "KRW" "MYR" "SGD" "PHP" "THB"
So basically I want to save a variable cursig such that it displays only the currencies with a signal of 1. So I'll have something like this:
cursig
[1] "GBP" " AUD" "CAD"....
And so on for whichever currency displays 1 for both signal functions. My problem is that
cursig[i] <- cur[i]
Returns the very last currency for which the signals are true. I know this is probably a very rookie mistake, but a nudge in the right direction would be much appreciated.
EDIT:
Here's the full function:
new.trend <- function(MergedData)
{
ret <- as.list(rep(NA, length(MergedData)))
ma.sig <- ma.crossover(MergedData)
pricebreak <- price.channel(MergedData)
sig <- which(!ma.sig[1,]==0)&which(!pricebreak[1,]==0) ## Retrieves signals
sig <- which(sig)
cursig <- character() #Preparing to save currency variables
for (i in 1:length(sig)) { #Calculates output variables based on active signals
x <- MergedData[[i]]
x <- xts(x[,-1], order.by=x[,1])
dev20 <- (x[,5]-SMA(x[,5], n=20))/x[,5]*100
dev50 <- (x[,5]-SMA(x[,5], n=50))/x[,5]*100
RSI <- RSI(x[,5], n=14)
cursig <- c(cursig, cur[1])
ret[[i]] <- na.omit(merge(tail(dev20, n=1L), tail(dev50, n=1L), tail(RSI, n=1L)))
}
na.omit(do.call(merge,ret))
}
print(new.trend(MergedData))
The reason I'm using a for() loop is because MergedData consits of 29 dataframes such that MergedData[[1] returns something like:
Date EUR.OPEN EUR.HIGH EUR.LOW EUR.CLOSE EUR.LAST
1 2016-08-30 1.1153 1.1192 1.1153 1.1161 1.1161
2 2016-08-29 1.1158 1.1208 1.1158 1.1189 1.1189
3 2016-08-28 1.1181 1.1341 1.1181 1.1198 1.1198
4 2016-08-27 1.1181 1.1341 1.1181 1.1198 1.1198
5 2016-08-26 1.1181 1.1341 1.1181 1.1198 1.1198
And so on for 29 currencies listed in cur.
Sample dput is here:
tzone = "", class = c("POSIXct",
"POSIXt")), PHP.OPEN = c(46.385, 46.283, 46.283, 46.283,
46.283, 46.33, 46.45, 46.45, 46.5, 46.29, 46.29, 46.29, 46.235,
46.28, 46.225, 46.445, 46.455, 46.455, 46.455, 46.365, 46.73,
46.85, 46.423, 46.05, 46.05, 46.05, 46.975, 46.03, 46.035,
46.915, 47.017, 47.017, 47.017, 47.05, 46.825, 47.105, 47.12,
47, 47, 47, 47.055, 46.015, 46.725, 46.675, 46.671, 46.671,
46.671, 47.019, 47, 47.055, 47.033, 47, 47, 47, 46.85, 46.765,
46.765, 46.753, 46.465, 46.465, 46.465, 46.035, 46.49, 45.93,
46.955, 46.51, 46.51, 46.51, 46.475, 46.365, 46.31, 46.3,
44.623, 44.623, 44.623, 46.285, 46.31, 46.073, 46.07, 46.06,
46.06, 46.06, 45.859, 46, 45.728, 46.2, 46.452, 46.452, 46.452,
46.53, 46.64, 46.653, 46.69, 46.614, 46.614, 46.614, 46.429,
46.63, 46.788, 46.69, 46.714, 46.714, 46.714, 46.705, 46.465,
46.325, 46.055, 46.55, 46.55, 46.55, 46.458, 46.53, 46.753,
47.085, 47.085, 47.085, 47.085, 47.118, 46.595, 46.845, 46.225,
46.66, 46.66, 46.66, 46.722, 46.64, 46.728, 46.683, 46.285,
46.285, 46.285, 46.224, 46.04, 46.055, 46.06, 46.049, 46.049,
46.049, 46.154, 45.903, 46.017, 46, 46.12, 46.12, 46.12,
46.07, 46.165, 46.153, 45, 45.95, 45.95, 45.95, 45.91, 46.02,
46.235, 46.325, 46.227, 46.227, 46.227, 46.227, 46.227, 46.16,
46, 46.168, 46.168, 46.168, 46.357, 46.475, 46.61, 46.439,
46.595, 46.595, 46.595, 46.653, 46.835, 46.285, 46.772, 46.861,
46.861, 46.861, 47.02, 47.225, 47.3, 47.525, 47.076, 47.076,
47.076, 47.62, 47.613, 47.575, 47.585, 47.552, 47.552, 47.552,
47.51, 47.45, 47.403, 47.435, 47.45, 47.45, 47.45, 47.375,
47.445, 47, 47.665, 47.665, 47.665, 47.665, 47.719, 47.825,
47.67, 47.623, 47.615, 47.615, 47.615, 47.717, 47.809, 47.869,
47.72, 47.8, 47.8, 47.8, 47.695, 47.67, 47.586, 47.635, 47.63,
47.63, 47.63, 47.55, 47.335, 47.2, 47.233, 46.92, 46.92,
46.92, 46.98, 46.82, 46.875, 47, 47.17, 47.17, 47.17), PHP.HIGH = c(46.535,
46.438, 46.438, 46.438, 46.438, 46.583, 46.645, 46.59, 46.702,
46.488, 46.488, 46.488, 46.41, 46.88, 46.88, 46.77, 46.865,
46.865, 46.865, 46.8, 46.865, 46.975, 47.02, 47.04, 47.04,
47.04, 47.075, 47.358, 47.487, 47.03, 47.135, 47.135, 47.135,
47.18, 47.228, 47.24, 47.228, 47.155, 47.155, 47.155, 47.23,
47.158, 46.96, 46.89, 47.055, 47.055, 47.055, 47.22, 47.435,
47.49, 47.32, 47.585, 47.585, 47.585, 47.112, 47.345, 47.345,
46.895, 47.065, 47.065, 47.065, 47.935, 47.98, 47.95, 47.183,
46.975, 46.975, 46.975, 46.587, 46.64, 46.388, 46.445, 46.475,
46.475, 46.475, 46.455, 46.479, 47.065, 46.222, 46.155, 46.155,
46.155, 46.388, 46.12, 46.265, 46.45, 46.982, 46.982, 46.982,
46.615, 46.79, 47.065, 46.825, 46.71, 46.71, 46.71, 46.788,
46.889, 46.925, 46.86, 46.86, 46.86, 46.86, 46.947, 46.705,
46.457, 46.655, 46.8, 46.8, 46.8, 46.715, 46.75, 47.205,
47.385, 47.385, 47.385, 47.385, 47.245, 47.132, 47.75, 47.041,
46.964, 46.964, 46.964, 46.878, 46.842, 46.94, 46.874, 46.68,
46.68, 46.68, 46.46, 46.225, 46.16, 46.2, 46.25, 46.25, 46.25,
46.306, 46.487, 46.14, 46.18, 46.266, 46.266, 46.266, 46.17,
46.338, 46.295, 46.105, 47.02, 47.02, 47.02, 46.085, 46.262,
46.439, 46.537, 46.463, 46.463, 46.463, 46.463, 46.463, 46.39,
46.577, 46.379, 46.379, 46.379, 46.58, 46.925, 46.83, 46.607,
46.795, 46.795, 46.795, 46.855, 47.025, 47.035, 46.925, 47.125,
47.125, 47.125, 47.252, 47.307, 47.5, 47.605, 47.603, 47.603,
47.603, 47.62, 47.717, 47.66, 47.705, 47.905, 47.905, 47.905,
47.595, 47.695, 47.59, 47.555, 47.74, 47.74, 47.74, 47.488,
47.632, 47.795, 47.757, 47.757, 47.757, 47.757, 47.8, 47.925,
47.79, 47.74, 47.775, 47.775, 47.775, 47.945, 47.995, 48.005,
47.9, 47.911, 47.911, 47.911, 47.958, 47.895, 47.755, 47.885,
47.78, 47.78, 47.78, 47.748, 47.55, 47.46, 47.335, 47.173,
47.173, 47.173, 47.14, 47.062, 47.188, 47.158, 47.17, 47.17,
47.17), PHP.LOW = c(46.385, 46.283, 46.283, 46.283, 46.283,
46.33, 46.45, 46.45, 46.5, 46.29, 46.29, 46.29, 46.235, 46.28,
46.225, 46.445, 46.455, 46.455, 46.455, 46.365, 46.73, 46.85,
46.423, 46.05, 46.05, 46.05, 46.975, 46.03, 46.035, 46.915,
47.017, 47.017, 47.017, 47.05, 46.825, 47.105, 47.12, 47,
47, 47, 47.055, 46.015, 46.725, 46.675, 46.671, 46.671, 46.671,
47.019, 47, 47.055, 47.033, 47, 47, 47, 46.85, 46.765, 46.765,
46.753, 46.465, 46.465, 46.465, 46.035, 46.49, 45.93, 46.955,
46.51, 46.51, 46.51, 46.475, 46.365, 46.31, 46.3, 44.623,
44.623, 44.623, 46.285, 46.31, 46.073, 46.07, 46.06, 46.06,
46.06, 45.859, 46, 45.728, 46.2, 46.452, 46.452, 46.452,
46.53, 46.64, 46.653, 46.69, 46.614, 46.614, 46.614, 46.429,
46.63, 46.788, 46.69, 46.714, 46.714, 46.714, 46.705, 46.465,
46.325, 46.055, 46.55, 46.55, 46.55, 46.458, 46.53, 46.753,
47.085, 47.085, 47.085, 47.085, 47.118, 46.595, 46.845, 46.225,
46.66, 46.66, 46.66, 46.722, 46.64, 46.728, 46.683, 46.285,
46.285, 46.285, 46.224, 46.04, 46.055, 46.06, 46.049, 46.049,
46.049, 46.154, 45.903, 46.017, 46, 46.12, 46.12, 46.12,
46.07, 46.165, 46.153, 45, 45.95, 45.95, 45.95, 45.91, 46.02,
46.235, 46.325, 46.227, 46.227, 46.227, 46.227, 46.227, 46.16,
46, 46.168, 46.168, 46.168, 46.357, 46.475, 46.61, 46.439,
46.595, 46.595, 46.595, 46.653, 46.835, 46.285, 46.772, 46.861,
46.861, 46.861, 47.02, 47.225, 47.3, 47.525, 47.076, 47.076,
47.076, 47.62, 47.613, 47.575, 47.585, 47.552, 47.552, 47.552,
47.51, 47.45, 47.403, 47.435, 47.45, 47.45, 47.45, 47.375,
47.445, 47, 47.665, 47.665, 47.665, 47.665, 47.719, 47.825,
47.67, 47.623, 47.615, 47.615, 47.615, 47.717, 47.809, 47.869,
47.72, 47.8, 47.8, 47.8, 47.695, 47.67, 47.586, 47.635, 47.63,
47.63, 47.63, 47.55, 47.335, 47.2, 47.233, 46.92, 46.92,
46.92, 46.98, 46.82, 46.875, 47, 47.17, 47.17, 47.17), PHP.CLOSE = c(46.46,
46.36, 46.36, 46.36, 46.36, 46.345, 46.535, 46.45, 46.58,
46.45, 46.45, 46.45, 46.28, 46.41, 46.88, 46.455, 46.6, 46.6,
46.6, 46.79, 46.75, 46.85, 46.835, 46.9, 46.9, 46.9, 47.02,
47.035, 46.961, 46.94, 47.11, 47.11, 47.11, 47.07, 47.18,
47.14, 47.15, 47.12, 47.12, 47.12, 47.077, 46.725, 46.94,
46.714, 46.85, 46.85, 46.85, 47.05, 47.21, 47.321, 47.31,
47.125, 47.125, 47.125, 47, 47.03, 47.03, 46.775, 46.915,
46.915, 46.915, 47.085, 46.965, 46.895, 47.03, 46.95, 46.95,
46.95, 46.51, 46.475, 46.38, 46.335, 46.425, 46.425, 46.425,
46.43, 46.43, 46.31, 46.08, 46.13, 46.13, 46.13, 46.055,
46.01, 46.11, 46.225, 46.465, 46.465, 46.465, 46.53, 46.64,
46.75, 46.75, 46.635, 46.635, 46.635, 46.69, 46.785, 46.92,
46.788, 46.75, 46.75, 46.75, 46.8, 46.66, 46.42, 46.46, 46.555,
46.555, 46.555, 46.647, 46.555, 46.757, 47.09, 47.09, 47.09,
47.09, 47.24, 47.08, 46.89, 46.965, 46.89, 46.89, 46.89,
46.77, 46.78, 46.76, 46.85, 46.645, 46.645, 46.645, 46.44,
46.225, 46.093, 46.185, 46.065, 46.065, 46.065, 46.25, 46.085,
46.018, 46.122, 46.135, 46.135, 46.135, 46.1, 46.2, 46.26,
46.08, 46.015, 46.015, 46.015, 46.07, 46.028, 46.35, 46.34,
46.395, 46.395, 46.395, 46.395, 46.395, 46.285, 46.33, 46.36,
46.36, 46.36, 46.38, 46.785, 46.83, 46.595, 46.62, 46.62,
46.62, 46.695, 46.855, 46.958, 46.92, 46.946, 46.946, 46.946,
47.125, 47.298, 47.35, 47.558, 47.515, 47.515, 47.515, 47.62,
47.625, 47.635, 47.619, 47.665, 47.665, 47.665, 47.55, 47.45,
47.573, 47.45, 47.74, 47.74, 47.74, 47.45, 47.47, 47.671,
47.665, 47.665, 47.665, 47.665, 47.775, 47.86, 47.685, 47.69,
47.65, 47.65, 47.65, 47.743, 47.815, 47.997, 47.89, 47.805,
47.805, 47.805, 47.935, 47.89, 47.67, 47.706, 47.745, 47.745,
47.745, 47.64, 47.542, 47.45, 47.269, 47.158, 47.158, 47.158,
47.01, 47.025, 46.89, 47.125, 47.17, 47.17, 47.17), PHP.LAST = c(46.46,
46.36, 46.36, 46.36, 46.36, 46.345, 46.535, 46.45, 46.58,
46.45, 46.45, 46.45, 46.28, 46.41, 46.88, 46.455, 46.6, 46.6,
46.6, 46.79, 46.75, 46.85, 46.835, 46.9, 46.9, 46.9, 47.02,
47.035, 46.961, 46.94, 47.11, 47.11, 47.11, 47.07, 47.18,
47.14, 47.15, 47.12, 47.12, 47.12, 47.077, 46.725, 46.94,
46.714, 46.85, 46.85, 46.85, 47.05, 47.21, 47.321, 47.31,
47.125, 47.125, 47.125, 47, 47.03, 47.03, 46.775, 46.915,
46.915, 46.915, 47.085, 46.965, 46.895, 47.03, 46.95, 46.95,
46.95, 46.51, 46.475, 46.38, 46.335, 46.425, 46.425, 46.425,
46.43, 46.43, 46.31, 46.08, 46.13, 46.13, 46.13, 46.055,
46.01, 46.11, 46.225, 46.465, 46.465, 46.465, 46.53, 46.64,
46.75, 46.75, 46.635, 46.635, 46.635, 46.69, 46.785, 46.92,
46.788, 46.75, 46.75, 46.75, 46.8, 46.66, 46.42, 46.46, 46.555,
46.555, 46.555, 46.647, 46.555, 46.757, 47.09, 47.09, 47.09,
47.09, 47.24, 47.08, 46.89, 46.965, 46.89, 46.89, 46.89,
46.77, 46.78, 46.76, 46.85, 46.645, 46.645, 46.645, 46.44,
46.225, 46.093, 46.185, 46.065, 46.065, 46.065, 46.25, 46.085,
46.018, 46.122, 46.135, 46.135, 46.135, 46.1, 46.2, 46.26,
46.08, 46.015, 46.015, 46.015, 46.07, 46.028, 46.35, 46.34,
46.395, 46.395, 46.395, 46.395, 46.395, 46.285, 46.33, 46.36,
46.36, 46.36, 46.38, 46.785, 46.83, 46.595, 46.62, 46.62,
46.62, 46.695, 46.855, 46.958, 46.92, 46.946, 46.946, 46.946,
47.125, 47.298, 47.35, 47.558, 47.515, 47.515, 47.515, 47.62,
47.625, 47.635, 47.619, 47.665, 47.665, 47.665, 47.55, 47.45,
47.573, 47.45, 47.74, 47.74, 47.74, 47.45, 47.47, 47.671,
47.665, 47.665, 47.665, 47.665, 47.775, 47.86, 47.685, 47.69,
47.65, 47.65, 47.65, 47.743, 47.815, 47.997, 47.89, 47.805,
47.805, 47.805, 47.935, 47.89, 47.67, 47.706, 47.745, 47.745,
47.745, 47.64, 47.542, 47.45, 47.269, 47.158, 47.158, 47.158,
47.01, 47.025, 46.89, 47.125, 47.17, 47.17, 47.17)), .Names = c("Date",
"PHP.OPEN", "PHP.HIGH", "PHP.LOW", "PHP.CLOSE", "PHP.LAST"
), row.names = c(NA, -243L), class = "data.frame"), structure(list(
Date = structure(c(1472533200, 1472446800, 1472360400,
1472274000, 1472187600, 1472101200, 1472014800, 1471928400,
1471842000, 1471755600, 1471669200, 1471582800, 1471496400,
1471410000, 1471323600, 1471237200, 1471150800, 1471064400,
1470978000, 1470891600, 1470805200, 1470718800, 1470632400,
1470546000, 1470459600, 1470373200, 1470286800, 1470200400,
1470114000, 1470027600, 1469941200, 1469854800, 1469768400,
1469682000, 1469595600, 1469509200, 1469422800, 1469336400,
1469250000, 1469163600, 1469077200, 1468990800, 1468904400,
1468818000, 1468731600, 1468645200, 1468558800, 1468472400,
1468386000, 1468299600, 1468213200, 1468126800, 1468040400,
1467954000, 1467867600, 1467781200, 1467694800, 1467608400,
1467522000, 1467435600, 1467349200, 1467262800, 1467176400,
1467090000, 1467003600, 1466917200, 1466830800, 1466744400,
1466658000, 1466571600, 1466485200, 1466398800, 1466312400,
1466226000, 1466139600, 1466053200, 1465966800, 1465880400,
1465794000, 1465707600, 1465621200, 1465534800, 1465448400,
1465362000, 1465275600, 1465189200, 1465102800, 1465016400,
1464930000, 1464843600, 1464757200, 1464670800, 1464584400,
1464498000, 1464411600, 1464325200, 1464238800, 1464152400,
1464066000, 1463979600, 1463893200, 1463806800, 1463720400,
1463634000, 1463547600, 1463461200, 1463374800, 1463288400,
1463202000, 1463115600, 1463029200, 1462942800, 1462856400,
1462770000, 1462683600, 1462597200, 1462510800, 1462424400,
1462338000, 1462251600, 1462165200, 1462078800, 1461992400,
1461906000, 1461819600, 1461733200, 1461646800, 1461560400,
1461474000, 1461387600, 1461301200, 1461214800, 1461128400,
1461042000, 1460955600, 1460869200, 1460782800, 1460696400,
1460610000, 1460523600, 1460437200, 1460350800, 1460264400,
1460178000, 1460091600, 1460005200, 1459918800, 1459832400,
1459746000, 1459659600, 1459573200, 1459486800, 1459400400,
1459314000, 1459227600, 1459141200, 1459054800, 1458968400,
1458882000, 1458795600, 1458709200, 1458622800, 1458536400,
1458450000, 1458363600, 1458277200, 1458190800, 1458104400,
1458018000, 1457931600, 1457848800, 1457762400, 1457676000,
1457589600, 1457503200, 1457416800, 1457330400, 1457244000,
1457157600, 1457071200, 1456984800, 1456898400, 1456812000,
1456725600, 1456639200, 1456552800, 1456466400, 1456380000,
1456293600, 1456207200, 1456120800, 1456034400, 1455948000,
1455861600, 1455775200, 1455688800, 1455602400, 1455516000,
1455429600, 1455343200, 1455256800, 1455170400, 1455084000,
1454997600, 1454911200, 1454824800, 1454738400, 1454652000,
1454565600, 1454479200, 1454392800, 1454306400, 1454220000,
1454133600, 1454047200, 1453960800, 1453874400, 1453788000,
1453701600, 1453615200, 1453528800, 1453442400, 1453356000,
1453269600, 1453183200, 1453096800, 1453010400, 1452924000,
1452837600, 1452751200, 1452664800, 1452578400, 1452492000,
1452405600, 1452319200, 1452232800, 1452146400, 1452060000,
1451973600, 1451887200, 1451800800, 1451714400, 1451628000
), tzone = "", class = c("POSIXct", "POSIXt")), THB.OPEN = c(34.53,
34.596, 34.506, 34.506, 34.506, 34.539, 34.573, 34.564,
34.607, 34.528, 34.528, 34.528, 34.531, 34.577, 34.52,
34.577, 34.696, 34.696, 34.696, 34.731, 34.738, 34.911,
34.901, 34.796, 34.796, 34.796, 34.886, 34.739, 34.74,
34.72, 34.8, 34.8, 34.8, 34.84, 34.951, 34.98, 34.905,
34.87, 34.87, 34.87, 34.95, 34.97, 34.931, 34.918, 34.907,
34.907, 34.907, 35.029, 35.13, 35.103, 35.049, 35.169,
35.169, 35.169, 35.145, 35.149, 35.012, 35.011, 35.06,
35.06, 35.06, 35.097, 35.175, 35.238, 35.257, 35.114,
35.114, 35.114, 35.146, 35.173, 35.15, 35.162, 35.225,
35.225, 35.225, 35.151, 35.24, 35.12, 35.16, 35.147,
35.147, 35.147, 35.085, 35.189, 35.217, 35.26, 35.545,
35.545, 35.545, 35.57, 35.64, 35.691, 35.69, 35.56, 35.56,
35.56, 35.571, 35.625, 35.664, 35.56, 35.622, 35.622,
35.622, 35.641, 35.486, 35.32, 35.341, 35.311, 35.311,
35.311, 35.217, 35.19, 35.193, 35.09, 35.126, 35.126,
35.126, 35.075, 34.99, 34.83, 34.83, 34.885, 34.885,
34.885, 35.007, 35.09, 35.08, 35.052, 35.02, 35.02, 35.02,
34.883, 34.825, 34.88, 35.01, 35.051, 35.051, 35.051,
35.024, 34.951, 35.005, 35.04, 35.09, 35.09, 35.09, 35.15,
35.214, 35.237, 35.12, 35.09, 35.09, 35.09, 35.159, 35.189,
35.323, 35.274, 35.265, 35.265, 35.265, 35.188, 34.917,
34.88, 34.85, 34.745, 34.745, 34.745, 34.77, 34.99, 35.07,
35.05, 35.064, 35.064, 35.064, 35.239, 35.287, 35.365,
35.349, 35.385, 35.385, 35.385, 35.476, 35.54, 35.588,
35.618, 35.63, 35.63, 35.63, 35.65, 35.69, 35.715, 35.717,
35.54, 35.54, 35.54, 35.537, 35.6, 35.59, 35.552, 35.228,
35.228, 35.228, 35.228, 35.3, 35.388, 35.495, 35.48,
35.48, 35.48, 35.55, 35.77, 35.579, 35.591, 35.684, 35.684,
35.684, 35.775, 35.77, 35.89, 35.925, 36.026, 36.026,
36.026, 36.235, 36.272, 36.26, 36.29, 36.28, 36.28, 36.28,
36.256, 36.237, 36.235, 36.25, 36.17, 36.17, 36.17, 36.226,
36.103, 36.08, 36.033, 36.02, 36.02, 36.02), THB.HIGH = c(34.655,
34.72, 34.601, 34.601, 34.601, 34.675, 34.69, 34.676,
34.764, 34.671, 34.671, 34.671, 34.69, 34.737, 34.65,
34.82, 34.86, 34.86, 34.86, 34.838, 34.967, 35.005, 35.065,
34.93, 34.93, 34.93, 35.039, 34.95, 34.84, 34.91, 34.92,
34.92, 34.92, 34.967, 35.074, 35.086, 35.08, 35, 35,
35, 35.088, 35.09, 35.04, 35.03, 35.085, 35.085, 35.085,
35.23, 35.257, 35.206, 35.225, 35.264, 35.264, 35.264,
35.239, 35.281, 35.198, 35.125, 35.16, 35.16, 35.16,
35.228, 35.295, 35.371, 35.435, 35.546, 35.546, 35.546,
35.244, 35.29, 35.24, 35.284, 35.356, 35.356, 35.356,
35.254, 35.39, 35.303, 35.295, 35.295, 35.295, 35.295,
35.24, 35.241, 35.327, 35.411, 35.64, 35.64, 35.64, 35.704,
35.77, 35.755, 35.8, 35.701, 35.701, 35.701, 35.68, 35.795,
35.787, 35.706, 35.736, 35.736, 35.736, 35.8, 35.625,
35.557, 35.461, 35.466, 35.466, 35.466, 35.34, 35.294,
35.267, 35.166, 35.193, 35.193, 35.193, 35.19, 35.184,
34.94, 34.934, 35.009, 35.009, 35.009, 35.16, 35.195,
35.222, 35.17, 35.095, 35.095, 35.095, 35.095, 34.949,
35.02, 35.11, 35.12, 35.12, 35.12, 35.211, 35.055, 35.07,
35.112, 35.234, 35.234, 35.234, 35.253, 35.31, 35.39,
35.29, 35.175, 35.175, 35.175, 35.262, 35.365, 35.44,
35.408, 35.365, 35.365, 35.365, 35.395, 35.13, 34.963,
34.952, 34.925, 34.925, 34.925, 34.975, 35.145, 35.15,
35.151, 35.26, 35.26, 35.26, 35.31, 35.393, 35.47, 35.495,
35.46, 35.46, 35.46, 35.559, 35.656, 35.655, 35.763,
35.707, 35.707, 35.707, 35.714, 35.759, 35.776, 35.781,
35.75, 35.75, 35.75, 35.63, 35.68, 35.671, 35.69, 35.64,
35.64, 35.64, 35.325, 35.428, 35.539, 35.612, 35.651,
35.651, 35.651, 35.755, 35.87, 35.771, 35.77, 35.861,
35.861, 35.861, 35.885, 35.874, 36.045, 36.055, 36.253,
36.253, 36.253, 36.29, 36.327, 36.325, 36.382, 36.374,
36.374, 36.374, 36.345, 36.338, 36.375, 36.345, 36.327,
36.327, 36.327, 36.35, 36.257, 36.177, 36.19, 36.033,
36.033, 36.033), THB.LOW = c(34.53, 34.596, 34.506, 34.506,
34.506, 34.539, 34.573, 34.564, 34.607, 34.528, 34.528,
34.528, 34.531, 34.577, 34.52, 34.577, 34.696, 34.696,
34.696, 34.731, 34.738, 34.911, 34.901, 34.796, 34.796,
34.796, 34.886, 34.739, 34.74, 34.72, 34.8, 34.8, 34.8,
34.84, 34.951, 34.98, 34.905, 34.87, 34.87, 34.87, 34.95,
34.97, 34.931, 34.918, 34.907, 34.907, 34.907, 35.029,
35.13, 35.103, 35.049, 35.169, 35.169, 35.169, 35.145,
35.149, 35.012, 35.011, 35.06, 35.06, 35.06, 35.097,
35.175, 35.238, 35.257, 35.114, 35.114, 35.114, 35.146,
35.173, 35.15, 35.162, 35.225, 35.225, 35.225, 35.151,
35.24, 35.12, 35.16, 35.147, 35.147, 35.147, 35.085,
35.189, 35.217, 35.26, 35.545, 35.545, 35.545, 35.57,
35.64, 35.691, 35.69, 35.56, 35.56, 35.56, 35.571, 35.625,
35.664, 35.56, 35.622, 35.622, 35.622, 35.641, 35.486,
35.32, 35.341, 35.311, 35.311, 35.311, 35.217, 35.19,
35.193, 35.09, 35.126, 35.126, 35.126, 35.075, 34.99,
34.83, 34.83, 34.885, 34.885, 34.885, 35.007, 35.09,
35.08, 35.052, 35.02, 35.02, 35.02, 34.883, 34.825, 34.88,
35.01, 35.051, 35.051, 35.051, 35.024, 34.951, 35.005,
35.04, 35.09, 35.09, 35.09, 35.15, 35.214, 35.237, 35.12,
35.09, 35.09, 35.09, 35.159, 35.189, 35.323, 35.274,
35.265, 35.265, 35.265, 35.188, 34.917, 34.88, 34.85,
34.745, 34.745, 34.745, 34.77, 34.99, 35.07, 35.05, 35.064,
35.064, 35.064, 35.239, 35.287, 35.365, 35.349, 35.385,
35.385, 35.385, 35.476, 35.54, 35.588, 35.618, 35.63,
35.63, 35.63, 35.65, 35.69, 35.715, 35.717, 35.54, 35.54,
35.54, 35.537, 35.6, 35.59, 35.552, 35.228, 35.228, 35.228,
35.228, 35.3, 35.388, 35.495, 35.48, 35.48, 35.48, 35.55,
35.77, 35.579, 35.591, 35.684, 35.684, 35.684, 35.775,
35.77, 35.89, 35.925, 36.026, 36.026, 36.026, 36.235,
36.272, 36.26, 36.29, 36.28, 36.28, 36.28, 36.256, 36.237,
36.235, 36.25, 36.17, 36.17, 36.17, 36.226, 36.103, 36.08,
36.033, 36.02, 36.02, 36.02), THB.CLOSE = c(34.558, 34.601,
34.565, 34.565, 34.565, 34.565, 34.618, 34.64, 34.67,
34.635, 34.635, 34.635, 34.605, 34.7, 34.575, 34.61,
34.81, 34.81, 34.81, 34.76, 34.751, 34.965, 34.974, 34.822,
34.822, 34.822, 34.927, 34.94, 34.75, 34.77, 34.83, 34.83,
34.83, 34.868, 34.97, 35.01, 35.05, 34.93, 34.93, 34.93,
34.995, 34.989, 35.01, 35.005, 34.94, 34.94, 34.94, 35.03,
35.16, 35.138, 35.11, 35.25, 35.25, 35.25, 35.173, 35.214,
35.134, 35.048, 35.086, 35.086, 35.086, 35.138, 35.23,
35.29, 35.35, 35.339, 35.339, 35.339, 35.173, 35.24,
35.173, 35.21, 35.235, 35.235, 35.235, 35.24, 35.25,
35.3, 35.18, 35.26, 35.26, 35.26, 35.21, 35.21, 35.23,
35.28, 35.629, 35.629, 35.629, 35.61, 35.67, 35.705,
35.75, 35.658, 35.658, 35.658, 35.6, 35.71, 35.73, 35.66,
35.679, 35.679, 35.679, 35.71, 35.6, 35.49, 35.37, 35.43,
35.43, 35.43, 35.32, 35.27, 35.236, 35.13, 35.149, 35.149,
35.149, 35.179, 35.184, 34.92, 34.841, 34.92, 34.92,
34.92, 35.02, 35.15, 35.16, 35.11, 35.04, 35.04, 35.04,
35.01, 34.86, 34.91, 35.03, 35.065, 35.065, 35.065, 35.12,
35.036, 35.02, 35.07, 35.12, 35.12, 35.12, 35.205, 35.256,
35.32, 35.263, 35.105, 35.105, 35.105, 35.185, 35.235,
35.426, 35.36, 35.27, 35.27, 35.27, 35.35, 35.118, 34.91,
34.89, 34.85, 34.85, 34.85, 34.78, 35.02, 35.132, 35.08,
35.16, 35.16, 35.16, 35.25, 35.32, 35.425, 35.42, 35.403,
35.403, 35.403, 35.51, 35.57, 35.625, 35.64, 35.64, 35.64,
35.64, 35.68, 35.7, 35.74, 35.755, 35.745, 35.745, 35.745,
35.548, 35.61, 35.61, 35.65, 35.58, 35.58, 35.58, 35.245,
35.36, 35.489, 35.51, 35.497, 35.497, 35.497, 35.56,
35.841, 35.76, 35.605, 35.73, 35.73, 35.73, 35.825, 35.79,
35.908, 36.021, 36.037, 36.037, 36.037, 36.263, 36.3,
36.27, 36.32, 36.366, 36.366, 36.366, 36.313, 36.25,
36.33, 36.28, 36.307, 36.307, 36.307, 36.285, 36.22,
36.15, 36.14, 36.02, 36.02, 36.02), THB.LAST = c(34.558,
34.601, 34.565, 34.565, 34.565, 34.565, 34.618, 34.64,
34.67, 34.635, 34.635, 34.635, 34.605, 34.7, 34.575,
34.61, 34.81, 34.81, 34.81, 34.76, 34.751, 34.965, 34.974,
34.822, 34.822, 34.822, 34.927, 34.94, 34.75, 34.77,
34.83, 34.83, 34.83, 34.868, 34.97, 35.01, 35.05, 34.93,
34.93, 34.93, 34.995, 34.989, 35.01, 35.005, 34.94, 34.94,
34.94, 35.03, 35.16, 35.138, 35.11, 35.25, 35.25, 35.25,
35.173, 35.214, 35.134, 35.048, 35.086, 35.086, 35.086,
35.138, 35.23, 35.29, 35.35, 35.339, 35.339, 35.339,
35.173, 35.24, 35.173, 35.21, 35.235, 35.235, 35.235,
35.24, 35.25, 35.3, 35.18, 35.26, 35.26, 35.26, 35.21,
35.21, 35.23, 35.28, 35.629, 35.629, 35.629, 35.61, 35.67,
35.705, 35.75, 35.658, 35.658, 35.658, 35.6, 35.71, 35.73,
35.66, 35.679, 35.679, 35.679, 35.71, 35.6, 35.49, 35.37,
35.43, 35.43, 35.43, 35.32, 35.27, 35.236, 35.13, 35.149,
35.149, 35.149, 35.179, 35.184, 34.92, 34.841, 34.92,
34.92, 34.92, 35.02, 35.15, 35.16, 35.11, 35.04, 35.04,
35.04, 35.01, 34.86, 34.91, 35.03, 35.065, 35.065, 35.065,
35.12, 35.036, 35.02, 35.07, 35.12, 35.12, 35.12, 35.205,
35.256, 35.32, 35.263, 35.105, 35.105, 35.105, 35.185,
35.235, 35.426, 35.36, 35.27, 35.27, 35.27, 35.35, 35.118,
34.91, 34.89, 34.85, 34.85, 34.85, 34.78, 35.02, 35.132,
35.08, 35.16, 35.16, 35.16, 35.25, 35.32, 35.425, 35.42,
35.403, 35.403, 35.403, 35.51, 35.57, 35.625, 35.64,
35.64, 35.64, 35.64, 35.68, 35.7, 35.74, 35.755, 35.745,
35.745, 35.745, 35.548, 35.61, 35.61, 35.65, 35.58, 35.58,
35.58, 35.245, 35.36, 35.489, 35.51, 35.497, 35.497,
35.497, 35.56, 35.841, 35.76, 35.605, 35.73, 35.73, 35.73,
35.825, 35.79, 35.908, 36.021, 36.037, 36.037, 36.037,
36.263, 36.3, 36.27, 36.32, 36.366, 36.366, 36.366, 36.313,
36.25, 36.33, 36.28, 36.307, 36.307, 36.307, 36.285,
36.22, 36.15, 36.14, 36.02, 36.02, 36.02)), .Names = c("Date",
"THB.OPEN", "THB.HIGH", "THB.LOW", "THB.CLOSE", "THB.LAST"
), row.names = c(NA, -243L), class = "data.frame"))
And the two functions listed within the original function is here:
price.channel <- function(MergedData)
{
ret <- as.list(rep(NA, length(MergedData)))
for (i in 1:length(MergedData)) {
x<- MergedData[[i]]
x <- xts(x[,-1], order.by=x[,1])
high <- runMax(x[,2], 20)
low <- runMin(x[,3], 20)
mid <- (high+low)/2
channel <- cbind(high, mid, low)
sig <- ifelse(sign(high-x[,5])>=0, sign(high-x[,5]), sign(low-x[,5]))
ret[[i]] <- sig
}
na.omit(do.call(merge, ret))
}
ma.crossover<- function(MergedData){
ma <- as.list(rep(NA, length(MergedData)))
for(i in 1:length(MergedData)) {
x <- MergedData[[i]]
x <- xts(x[,-1], order.by=x[,1])
ma20 <- SMA(x[,3], n=20)
ma50 <- SMA(x[,3], n=50)
ma[[i]] <- sign(ma20 - ma50)
}
na.omit(do.call(merge, ma))
}
And I want to create a table from new.trend with the following:
out.trend <- matrix(new.trend(MergedData), ncol = 3, byrow = TRUE, dimnames = list(paste0(cursig), c("% dev from 20MA", "% dev from 20MA", "RSI")))
I think manotheshark's answer is right about not needing a for loop and using intersect(), you could do it like this without relying on names():
The dummy data:
ma.sig <- read.table(text = "Eur JPY GBP CHF AUD CAD NZD SEK NOK
1 0 1 0 1 1 0 0 0", header = T)
pricebreak <- read.table(text = "Eur JPY GBP CHF AUD CAD NZD SEK NOK
1 0 1 0 1 1 0 1 1", , header = T)
cur <- c("EUR", "JPY","GBP", "CHF", "AUD", "CAD", "NZD", "SEK", "NOK", "CZK", "HUF", "ILS")
Manotheshark's method, without names():
sig <- intersect(which(!ma.sig[1,]==0), which(!pricebreak[1,]==0)) ## Retrieves signals
sig
[1] 1 3 5 6
cur[sig]
"EUR" "GBP" "AUD" "CAD"
Or your idea for a for loop with my comment:
cursig <- character()
for (i in sig) { #not 1:length(sig) thats always 1,2,3... in order
cursig <- c(cursig, cur[i])
}
cursig
[1] "EUR" "GBP" "AUD" "CAD"
If I understand what you're trying to get, a for loop should not be required. You can index the vectors on the conditions you're looking for
names(ma.sig[ma.sig == 1])
names(price.break[price.break == 1])
This will return the names that meet both conditions
intersect(names(ma.sig[ma.sig == 1]), names(price.break[price.break == 1]))
[1] "Eur" "GBP" "AUD" "CAD"

How to create a table of cumulative distribution in R?

I have plotted cumulative distribution of speeds using ecdf but I also want to get the output of cumulative probability as a table like this:
Speed Cumulative Probability
40 0.20
45 0.45
55 0.51
60 0.70
70 0.90
80 1.00
For my data, when I use ecdf it gives me following (Note that 'cc' is my original data frame):
> ccf <- subset(cc, cc$svel>=55 & cc$Headway>=4)
> cdf<- ecdf(ccf$svel)
> cdf
Empirical CDF
Call: ecdf(ccf$svel)
x[1:356] = 55, 55.01, 55.02, ..., 76.76, 76.8
How can I get the table like the example above? Please note that I tried 'cumsum' but it only gives the cumulative frequency whereas I need cumulative probability.
EDIT
Here's my data:
dput(ccf$svel)
c(67.9, 67.62, 67.37, 67.19, 67.04, 66.93, 66.83, 66.74, 66.65,
66.55, 66.46, 66.36, 66.25, 66.12, 65.97, 61.12, 61.2, 61.29,
61.39, 61.49, 61.58, 61.66, 61.73, 61.79, 57.98, 57.73, 57.5,
57.29, 57.1, 56.92, 56.75, 56.59, 56.45, 56.32, 56.19, 58, 58.18,
58.36, 58.52, 58.69, 56.28, 56.19, 56.08, 55.96, 55.83, 55.68,
55.52, 55.34, 55.15, 58.58, 58.89, 59.17, 59.4, 59.58, 55.01,
55.14, 55.23, 55.3, 55.36, 55.41, 55.47, 55.53, 55.59, 55.66,
55.74, 55.83, 55.92, 56.03, 56.16, 56.3, 56.44, 56.58, 56.71,
56.82, 56.91, 56.98, 57.03, 57.06, 57.07, 57.07, 57.06, 57.04,
57.02, 55.05, 55.22, 55.39, 55.56, 55.73, 55.92, 56.11, 56.31,
56.53, 56.77, 57.02, 57.28, 57.54, 57.79, 58, 58.18, 58.32, 58.43,
58.5, 58.56, 58.6, 58.64, 58.68, 58.73, 58.8, 58.86, 58.92, 58.97,
59.01, 59.03, 59.05, 59.05, 59.04, 59.02, 58.99, 58.97, 58.95,
55.1, 55.39, 55.68, 55.97, 56.24, 56.48, 56.68, 56.82, 56.9,
56.94, 56.96, 56.97, 56.99, 57.02, 57.07, 57.14, 57.22, 57.3,
57.37, 57.41, 57.45, 57.48, 57.51, 57.56, 57.62, 57.69, 57.77,
57.86, 57.95, 58.06, 58.17, 58.29, 58.42, 58.53, 58.64, 58.74,
58.83, 58.91, 58.98, 55.01, 55.08, 55.15, 55.22, 55.3, 55.37,
55.45, 55.53, 55.62, 55.73, 55.85, 55.99, 56.14, 56.31, 56.49,
56.67, 56.87, 57.05, 57.22, 57.37, 57.51, 57.65, 57.79, 57.95,
58.13, 58.3, 58.47, 58.63, 58.78, 58.91, 59.03, 59.14, 59.24,
59.34, 59.43, 59.53, 59.62, 59.72, 59.81, 59.9, 59.98, 60.07,
60.15, 60.22, 60.31, 60.39, 60.47, 60.56, 60.65, 60.75, 60.86,
60.98, 61.11, 61.24, 61.39, 61.54, 61.71, 61.89, 62.09, 62.31,
62.56, 62.84, 63.14, 63.46, 63.78, 64.08, 64.81, 64.84, 64.85,
64.87, 64.89, 64.92, 64.94, 64.97, 65, 65.02, 65.04, 65.07, 65.11,
65.15, 65.17, 65.18, 65.17, 65.15, 65.13, 65.1, 65.06, 65.01,
64.96, 64.9, 64.84, 64.79, 64.76, 55.04, 55.15, 55.25, 55, 55.23,
55.45, 55.68, 55.9, 56.69, 56.74, 55, 55, 55, 55, 55, 55.01,
55.26, 55.51, 55.77, 56.02, 56.28, 56.56, 56.84, 57.13, 57.42,
57.7, 57.98, 58.25, 58.49, 58.73, 58.94, 59.13, 59.29, 59.4,
59.48, 59.5, 59.48, 59.42, 59.31, 59.17, 59, 58.8, 58.6, 58.38,
58.17, 57.96, 57.77, 57.59, 57.44, 57.31, 57.21, 57.13, 57.07,
57.04, 57.03, 57.04, 57.07, 57.11, 57.18, 57.26, 57.34, 57.43,
57.51, 57.59, 57.68, 57.78, 57.88, 57.99, 58.08, 58.16, 58.22,
58.27, 58.3, 58.31, 58.31, 58.3, 58.27, 58.25, 58.22, 58.18,
58.14, 58.08, 58.01, 57.93, 57.84, 57.72, 57.59, 57.43, 57.27,
57.1, 56.93, 56.77, 56.63, 56.5, 56.38, 56.28, 56.19, 56.12,
56.05, 55.99, 55.94, 55.9, 55.88, 55.86, 55.85, 55.86, 55.87,
55.89, 55.9, 55.91, 55.91, 55.88, 55.84, 55.78, 55.71, 55.63,
55.56, 55.5, 55.45, 55.4, 55.37, 55.34, 55.32, 55.3, 55.29, 55.27,
55.26, 55.26, 55.25, 55.25, 55.26, 55.26, 55.27, 55.28, 55.29,
55.31, 55.33, 55.36, 55.39, 55.02, 55.07, 55.12, 55.16, 55.21,
55.26, 55.31, 55.04, 55.21, 55.38, 55.54, 55.71, 55.88, 56.05,
56.21, 56.38, 56.54, 56.71, 56.88, 57.04, 57.2, 57.35, 55.46,
55.59, 55.74, 55.92, 56.11, 56.32, 56.54, 56.77, 57.02, 57.28,
55.22, 55.28, 55.35, 55.42, 55.5, 55.58, 55.68, 55.78, 55.88,
56, 55.15, 55.45, 55.72, 55.94, 56.11, 56.22, 56.29, 56.33, 56.36,
56.4, 56.45, 56.51, 56.59, 56.69, 56.81, 56.95, 57.11, 57.27,
57.44, 57.61, 57.78, 57.95, 58.12, 58.29, 58.46, 58.63, 58.79,
58.94, 59.08, 59.21, 59.32, 59.41, 55.13, 55.3, 55.47, 55.65,
55.83, 56.02, 56.22, 56.43, 56.66, 56.9, 55.17, 56.02, 56.11,
56.21, 56.32, 56.42, 56.52, 57.18, 57.29, 57.42, 76.27, 76.28,
76.3, 76.33, 76.37, 76.41, 76.47, 76.54, 76.62, 76.7, 76.76,
76.8, 76.8, 55.08, 55.16, 55.24, 55.32, 55.4, 55.48, 55.12, 55.39,
55.67, 55.94, 56.21, 56.47, 56.72, 56.97, 57.19, 57.4, 57.58,
57.73, 57.87, 57.99, 58.11)
Here is a function that will do it:
cumprob <- function(y) {
fun <- function(y, x) length(y[y<x])/length(y)
prob<-sapply(y, fun, y=y)
data<- data.frame(value=unique(y[order(y)]), prob=unique(prob[order(prob)]))
}
Testing in your data (here I called it data):
cp<-cumprob(data)
head(cp)
value prob
1 55.00 0.00000000
2 55.01 0.01156069
3 55.02 0.01734104
4 55.04 0.01926782
5 55.05 0.02312139
6 55.07 0.02504817
Plot:
plot(cp)
Another quick and informal way I find pretty handy is using the hist function to automatically cut the data and get the midpoints.
Using your data as data:
h <- hist(data)
cum.prob <- data.frame(value=h$mids, prob=cumsum(h$counts)/sum(h$counts))
That gives you:
cum.prob
value prob
1 55 0.2793834
2 57 0.6319846
3 59 0.8285164
4 61 0.8786127
5 63 0.8921002
6 65 0.9479769
7 67 0.9749518
8 69 0.9749518
9 71 0.9749518
10 73 0.9749518
11 75 0.9749518
12 77 1.0000000

Resources