私はゾウアザラシの潜水中に収集されたさまざまな変数の大規模なデータセットを扱っています。データを細かいスケール (20 秒間隔) で分析したいと考えています。データを 20 秒間隔にビン化したいのですが、基本的には 20 秒ごとに平均を取得したいので、これらのデータ間隔でさらに分析を実行できます。ただし、別のダイビングからの情報をビニングしないように、データをダイビング # でグループ化する必要があります。
これまでに試した方法は次の 3 つです。
period.apply()
しかし、この機能でグループ化することはできません。split()
ダイビング#でデータをサブセット化しますが、これらのサブセット内で20秒間隔で異なる列の平均を計算する方法を見つけることができないようです.- openair パッケージを使用しています
timeaverage()
が、引き続きエラーが発生します (以下のコードを参照)。
以下は、データがどのように見えるか、および私が試したコードです。各 20 秒のウィンドウの深さ、MSA、rate_s、および HR の平均値が必要です。
> head(seal_dives)
datetime seal_ID Depth MSA D_phase diveNum rate_s HR
1 2018-04-06 14:47:51 Congaree 4.5 0.20154042 D 1 NA 115.3846
2 2018-04-06 14:47:51 Congaree 4.5 0.20154042 D 1 NA 117.6471
3 2018-04-06 14:47:52 Congaree 4.5 0.11496760 D 1 NA 115.3846
4 2018-04-06 14:47:52 Congaree 4.5 0.11496760 D 1 NA 122.4490
5 2018-04-06 14:47:53 Congaree 4.5 0.05935992 D 1 NA 113.2075
6 2018-04-06 14:47:53 Congaree 4.5 0.05935992 D 1 NA 113.2075
#openair package using timeaverage, results in error message
> library(openair)
> seal_20<-timeAverage(
seal_dives,
avg.time = "20 sec",
data.thresh = 0,
statistic = "mean",
type = c("diveNum","D_phase"),
percentile = NA,
start.date = NA,
end.date = NA,
vector.ws = FALSE,
fill = FALSE
)
Can't find the variable(s) date
Error in checkPrep(mydata, vars, type = "default", remove.calm = FALSE, :
#converting to time series and using period.apply(), but can't find a way to group them by dive #, or use split() then convert to time series.
#create a time series data class from our data frame
> seal_dives$datetime<-as.POSIXct(seal_dives$datetime,tz="GMT")
> seal_xts <- xts(seal_dives, order.by=seal_dives[,1])
> seal_20<-period.apply(seal_xts$Depth, endpoints(seal_xts$datetime, "seconds", 20), mean)
#split data by dive # but don't know how to do averages over 20 seconds
> seal_split<-split(seal_dives, seal_dives$diveNum)
インターネット上でまだ見つけていない魔法のような方法があるのかもしれませんし、私の方法の 1 つが間違っているだけかもしれません。