0

走っているときの時間と距離を参照する一連のデータがあります...そのため、時間と距離に関連する 2 つの列があります。全体で3000m走ったとしましょう。私が欲しいのは、30秒間隔で移動した平均距離です...したがって、0〜30秒、30〜60秒などから移動した平均距離が必要です....

次のコードを実行しました。

tapply(data$Distance,cut(data$Time,pretty(range(data$Time),high.u.bias=0.1)),mean)

しかし、これにより200秒間隔で平均が得られました...どうすればそれを変更できますか?

4

1 に答える 1

1

あなたのカットステートメントはおそらく次のようなものでなければなりません

# cutting every 30 seconds, starting at 0 
#    and going up to 30 seconds more than max of Times
cut(dat$Times, breaks=seq(0, max(dat$Times)+30, 30))
# if your time is in minutes, replace 30 with 0.5 

# Then you can assign it into your data frame if you'd like, 
#  but not necessary

cuts <- cut(dat$Times, breaks=seq(0, max(dat$Times)+30, 30))
by(dat$Dist, cuts, mean)

datはあなたのデータフレームでDistあり、あなたが平均化したいベクトルであると仮定していますTimes.

于 2013-02-19T07:27:24.100 に答える