r - 如何使用另一列计算 r 中的时间序列列?
问题描述
我是 r 的新手,我正在尝试计算一些基本的东西。我有 2 个时间序列列,时间和速度,在数据框中我正在尝试添加加速度列但不知道该怎么做:
df_x$Acceleration <- df_x$Velocity.....
我想使用的时间序列加速公式是:
基本上我有一个问题如何计算分子。
解决方案
How about
t.plus.one <- 1:nrow(df_x) + 1
t.minus.one <- 1:nrow(df_x) - 1
t <- 1:nrow(df_x)
df_x$Acceleration <- (df_x$Velocity[t.plus.one] - df_x$Velocity[t.minus.one]) / t
This will of course lead to an error, because the indices are not in range. However, you can easily fix that buy constructing the df
such that this does not occur.
推荐阅读
- javascript - 子组件中的可观察输入为空。为什么?
- runtime - 平均运行时间以进行性能分析
- java - 如何覆盖 javax.persistence.AttributeConverter
- javascript - 在javascript上按对象属性对数组进行排序
- bulma - Bulma .field-div 在移动设备上左对齐
- jquery - jquery 中所有 Radiobuttonlist 事件的通用事件
- sql - 使用用户定义的表类型从 excel 到 SQL 的 MVC 300K 行数据表 - 操作数类型冲突
- javascript - React Native 与 Animated 同步声音
- google-cloud-platform - 如何将角色绑定添加到特定的 memorystore 实例?
- r - 使用 plm 包时如何解决“系统在计算上是奇异的:倒数条件数 = 3.12737e-31”错误消息