[英]Create a new column based on the sum of values from another column, with dplyr
[英]How to create a new column with values from another column with index-1
我的最终目标是使用日志返回数据来预测未来的数据。 我尝试通过首先将日志返回数据转换为日志数据,然后是 exp(log data) 来实现这一点。 但是我无法将日志返回数据转换为日志数据。
log = log return + logy(t) --> 我有一个 log return 数据列,我正在尝试创建一个新列 (logy(t)),它采用 index = index-1 的日志数据的值。
例如,如果日志数据为 2、3、4、5、6,则 logy(t) 应为截距、2、3、4、5。
这是我的处理方法:
name$logyt<-name[row-1]["logdata"]
logyt<-as.numeric(unlist(logyt))
forecast<-predict(model3,newdata=name[205:221,])
model3forecast.ts<-ts(exp(forecast+logyt))
model 3 是时间序列,model3forecast.ts 应该是根据历史日志返回数据预测的时间序列。 我现在被困在创建列 logy(t) 上。
非常感谢!
dplyr
的一种暂定解决方案:
> library(magrittr)
> library(dplyr)
>
> dat <- data.frame(x = 1:6)
>
> dat1 <- dat %>%
+ mutate(x1 = lag(x))
>
> dat1
x x1
1 1 NA
2 2 1
3 3 2
4 4 3
5 5 4
6 6 5
这是你想要的?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.