data.frame
@Jase_は、データが;の場合にこれを行う方法の例を示しています。ただし、コメントと最初の使用の試みで、これはクラスdput
のオブジェクトであると示しました。zoo
これがzoo
解決策です(Jase_の答えから概念的に借用します)。index
オブジェクトの属性を利用しzoo
ます。
# First, read in your data as a zoo object via "copy and paste"
require(zoo)
t = read.zoo(text=' Time Depths ifc if lat lon
"7814" "2012-03-15 04:45:09-05" 4816 1040 5410 43.213628 -92.27727
"7815" "2012-03-15 04:30:04-05" 4813 1040 5410 43.213628 -92.27727
"7816" "2012-03-15 04:15:14-05" 4807 1040 5410 43.213628 -92.27727
"7817" "2012-03-15 04:00:09-05" 4809 1040 5410 43.213628 -92.27727
"7818" "2012-03-15 03:45:04-05" 4819 1040 5410 43.213628 -92.27727
"7819" "2012-03-15 03:30:15-05" 4816 1040 5410 43.213628 -92.27727
"7820" "2012-02-25 14:45:07-06" 4862 1040 5410 43.213628 -92.27727
"7821" "2012-02-25 14:30:02-06" 4858 1040 5410 43.213628 -92.27727
"7822" "2012-02-25 14:15:13-06" 4852 1040 5410 43.213628 -92.27727
"7823" "2012-02-25 14:00:08-06" 4860 1040 5410 43.213628 -92.27727
"7824" "2012-02-25 13:45:03-06" 4855 1040 5410 43.213628 -92.27727
"7825" "2012-02-25 13:30:13-06" 4869 1040 5410 43.213628 -92.27727
"7826" "2012-02-25 13:15:08-06" 4868 1040 5410 43.213628 -92.27727
"7827" "2012-02-25 13:00:03-06" 4873 1040 5410 43.213628 -92.27727
', tz="")
マージされた出力の2行のみ:
# Modify your index as per Jase_'s answer
index(t) = index(t) - as.numeric(format(index(t), "%S"))
# Merge with an empty zoo object that has an index
# of all the dates that you need.
t.merged = merge(t, zoo(, seq(from=index(t)[1],
to=index(t)[length(index(t))],
by="15 min")))
出力がどのようになるか見てみましょう:
head(t.merged, 10L)
#
# 2012-02-25 13:00:00 4873 1040 5410 43.21363 -92.27727
# 2012-02-25 13:15:00 4868 1040 5410 43.21363 -92.27727
# 2012-02-25 13:30:00 4869 1040 5410 43.21363 -92.27727
# 2012-02-25 13:45:00 4855 1040 5410 43.21363 -92.27727
# 2012-02-25 14:00:00 4860 1040 5410 43.21363 -92.27727
# 2012-02-25 14:15:00 4852 1040 5410 43.21363 -92.27727
# 2012-02-25 14:30:00 4858 1040 5410 43.21363 -92.27727
# 2012-02-25 14:45:00 4862 1040 5410 43.21363 -92.27727
# 2012-02-25 15:00:00 NA NA NA NA NA
# 2012-02-25 15:15:00 NA NA NA NA NA
tail(t.merged, 10L)
#
# 2012-03-15 02:30:00 NA NA NA NA NA
# 2012-03-15 02:45:00 NA NA NA NA NA
# 2012-03-15 03:00:00 NA NA NA NA NA
# 2012-03-15 03:15:00 NA NA NA NA NA
# 2012-03-15 03:30:00 4816 1040 5410 43.21363 -92.27727
# 2012-03-15 03:45:00 4819 1040 5410 43.21363 -92.27727
# 2012-03-15 04:00:00 4809 1040 5410 43.21363 -92.27727
# 2012-03-15 04:15:00 4807 1040 5410 43.21363 -92.27727
# 2012-03-15 04:30:00 4813 1040 5410 43.21363 -92.27727
# 2012-03-15 04:45:00 4816 1040 5410 43.21363 -92.27727
NA
しかし、これはあなたがやりたかったように値を置き換えるものではありません。