2013-02-19 102 views
0

我有一組數據指的是我的時間和我的距離,因爲我運行...所以我有2列與時間和距離有關。假設我跑了3000米。我想要的是我以30秒間隔旅行的平均距離......因此我想要我從0-30秒,30-60秒等旅行的平均距離......R編程幫助計算不同時間間隔的平均值

我做了以下代碼:

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

但是這給了我200秒間隔的平均值......我該如何改變這種情況?

+0

向我們展示您的數據(或者更好地使用'dput'粘貼您的數據)以便與您一起工作。 – Arun 2013-02-19 06:37:10

+0

可愛..你應該編輯你以前的問題。 http://stackoverflow.com/questions/14949819/r-programming-seperating-data-into-bins-and-calculating-averages – N8TRO 2013-02-19 06:53:05

+2

@NathanG噢人,我也努力在這個答案太... – 2013-02-19 07:03:41

回答

0

你切聲明或許應該像

# 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的載體,以及...你這個想法。

+0

感謝這個ricardo ......我想知道是否有可能繪製這些數據......就像中斷與切割(這是平均值)? – Blake43 2013-02-19 10:00:52

+0

你可以繪製任何你想要的東西;)你可能想把它作爲自己的問題發佈 – 2013-02-19 22:03:12