我有一组定期进行的测量数据,但其中有些数据缺失:
measurement_date value
1 2011-01-17 13:00:00 5
2 2011-01-17 13:04:00 5
3 2011-01-17 13:08:00 7
4 2011-01-17 13:12:00 8
5 2011-01-17 13:16:00 4
6 2011-01-17 13:24:00 6
7 2011-01-17 13:28:00 5
8 2011-01-17 13:32:00 6
9 2011-01-17 13:36:00 9
10 2011-01-17 13:40:00 8
11 2011-01-17 13:44:00 6
12 2011-01-17 13:48:00 6
13 2011-01-17 13:52:00 4
14 2011-01-17 13:56:00 6
我有一个函数,将处理值并可以处理缺失的值,但是行必须存在,因此我正在生成一个数组,每分钟都有一行,像这样:
times <- timeSequence(from=.., length=60, by="min")
现在我每小时有一行数据,但我需要合并这些数据。我尝试了以下代码,但效果不太对:
lapply(times, function(time) {
n <- as.numeric(time)
v <- Position(function(candidate) {
y <- as.numeric(candiated)
n == y
}
.. insert the value into the row here ..
}
但是我只收到错误和警告信息。我这样做是对问题的正确解决方法吗?我真的想要一个“完整”的数组,每分钟都有值,因为将会运行许多不同的函数来读取该数据,并且如果它们可以假定一切都在那里,那么实现它们会更容易。