r - How to duplicate data based on matches in two different columns
问题描述
I have accelerometer data sampled at 12.5Hz. For one dataset (X1), I have compressed these datapoints down into 1 second intervals, but I now need to recombine it with another column (X2) (sampled at 12.5Hz) to generate an equation. I want to duplicate the values in X1 if the time data matches with X2
My files currently look something like this
X1
Time Accx1
2019-03-28 07:47:07 5
2019-03-28 07:47:08 1
2019-03-28 07:47:09 7
X2
Time Accx2
2019-03-28 07:47:07 2
2019-03-28 07:47:07 8
2019-03-28 07:47:07 1
2019-03-28 07:47:07 9
2019-03-28 07:47:07 1
2019-03-28 07:47:07 1
2019-03-28 07:47:07 2
2019-03-28 07:47:07 3
2019-03-28 07:47:07 1
And I want them to look like this:
Time Accx1 Accx2
2019-03-28 07:47:07 5 2
2019-03-28 07:47:07 5 8
2019-03-28 07:47:07 5 1
2019-03-28 07:47:07 5 9
2019-03-28 07:47:07 5 1
2019-03-28 07:47:07 5 1
2019-03-28 07:47:07 5 2
2019-03-28 07:47:07 5 3
2019-03-28 07:47:07 5 1
解决方案
我相信您正在寻找合适的加入。这应该有效:
merge(X1, X2, by = "Time", all.x = FALSE, all.y = TRUE)
推荐阅读
- html - 电子邮件中的可点击 HTML 表格
- c# - MailMessage 中的 AlternateView 和附件有什么区别?
- struct - 为什么某些结构类型让我们设置只能是某个值的成员?
- mysql - 我应该如何在 MySQL 中为一对多关系构建数据
- java - Quartz 作业未启动 - Tomcat 服务器
- office-js - 如何使用新的 Office 插件以编程方式搜索和替换 Word 中的字体颜色
- python - 如何修复 if 语句以使用字符串?
- c++ - 从精灵表中以 sfml 动画精灵
- powershell - foreach 循环中是否存在“如果有”?
- jenkins-pipeline - 使詹金斯并行块更容易被人类理解