In the following code I use apply & order to give a relative rank, by row, of the strength of the 10 elements in each row of MyData. There are 16 rows and the dimension of MyData is 16x10 with dates (the xts index) vertically. The output of my apply/order statement is however reversed with the dates as columns names and 16 columns by 10 rows.
How can I get MyRank created in an xts format which I'd be able to easily cbind with price data or other xts elements?
Thanks
MyData = structure(c(0.127, 0.146, 0.175, 0.194, 0.181, 0.164, 0.143,
0.141, 0.116, 0.094, 0.095, 0.046, 0.062, 0.051, 0.039, 0.027,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
0.042, 0.053, 0.083, 0.1, 0.068, 0.037, 0.016, 0.024, 0.004,
-0.023, -0.025, -0.056, -0.028, -0.037, -0.059, -0.061, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.159,
0.166, 0.164, 0.218, 0.218, 0.182, 0.201, 0.197, 0.176, 0.134,
0.164, 0.147, 0.12, 0.07, 0.149, 0.147, 0.113, 0.127, 0.153,
0.257, 0.275, 0.183, 0.212, 0.17, 0.171, 0.09, 0.128, 0.064,
0.07, 0.06, 0.098, 0.093, 0.235, 0.23, 0.297, 0.302, 0.27, 0.245,
0.253, 0.247, 0.215, 0.165, 0.13, 0.086, 0.156, 0.13, 0.103,
0.114, 0.247, 0.253, 0.301, 0.387, 0.387, 0.35, 0.302, 0.319,
0.282, 0.261, 0.205, 0.151, 0.23, 0.181, 0.167, 0.157, 0.057,
0.112, 0.129, 0.1, 0.087, 0.108, 0.115, 0.07, 0.066, 0.025, 0.015,
-0.01, 0.02, 0.005, 0.009, 0.009), .indexCLASS = "Date", .indexTZ = "UTC", tclass = "Date", tzone = "UTC", class = c("xts",
"zoo"), index = structure(c(1009756800, 1009929600, 1010016000,
1010102400, 1010361600, 1010448000, 1010534400, 1010620800, 1010707200,
1010966400, 1011052800, 1011139200, 1011225600, 1011312000, 1011657600,
1011744000), tzone = "UTC", tclass = "Date"), .Dim = c(16L, 10L
), .Dimnames = list(NULL, c("DIA", "DVY", "EEM", "EFA", "EPP",
"EWA", "EWC", "EWG", "EWH", "EWI")))
dim(MyData)
is.xts(MyData)
MyRank = apply(MyData, 1, order, decreasing=TRUE)
dim(MyRank)
is.xts(MyRank)
colnames(MyRank) == index(MyData)