我有以下tbl_time对象:
library(tidyquant)
data <- structure(list(index = structure(c(13915, 13916, 13917, 13920,
13921, 13922, 13923, 13924, 13927, 13928), class = "Date"), zadnja = c(305.55,
298.02, 291.8, 294.98, 296.44, 296, 294, 290.65, 288, 291.99),
ma_1 = c(314.182857142857, 311.614285714286, 308.085714285714,
305.225714285714, 301.86, 299.145714285714, 296.684285714286,
294.555714285714, 293.124285714286, 293.151428571429), ma_2 = c(323.297142857143,
321.304761904762, 318.885238095238, 316.503333333333, 314.429047619048,
312.519047619048, 310.757142857143, 308.695714285714, 306.695238095238,
305.504285714286), macd = c(-3.37207220810237, -3.59709986407118,
-3.89692069355047, -4.01283868533963, -4.02460932284664,
-4.00256141038603, -3.99475081263415, -4.03423844455097,
-4.09302794203064, -3.98985583452542), dn = c(300.938100803014,
298.535273326249, 295.819794246054, 292.268047445615, 290.856476276663,
289.554088576577, 288.156637290461, 287.077449069052, 284.813011332112,
282.81163022933), up = c(345.027565863653, 343.196726673751,
340.87853908728, 339.114619221052, 336.353190390004, 334.237244756756,
332.065029376206, 329.277884264281, 328.386322001221, 328.18636977067
), pctB = c(0.14323676918361, 0.0329454872184538, -0.0404611265984324,
-0.0802203299662945, 0.105359778541273, 0.166637992029882,
0.141203744470954, 0.121149246620224, 0.102440123690646,
0.169294704094218), ema = c(309.678489813407, 303.849244906704,
297.824622453352, 296.402311226676, 296.421155613338, 296.210577806669,
295.105288903334, 292.877644451667, 290.438822225834, 291.214411112917
)), row.names = c(NA, -10L), ticker = "HT", index_quo = ~index, index_time_zone = "UTC", class = c("tbl_time",
"tbl_df", "tbl", "data.frame"))
我可以创建新的差异列:
data <- tidyquant::tq_mutate_(data, select = cls, mutate_fun = diff.xts)
但不能执行相同的内部函数,即使用字符串作为列名:
cls = "zadnja"
data <- tidyquant::tq_mutate_(data, select = cls, mutate_fun = diff.xts)
它返回错误:
Error in match(x, table, nomatch = 0L) :
'match' requires vector arguments
我还想更改列名。在上面的示例中,如果我想更改列“ zadnja”,则添加新列“ zadnja.1”