Pergunta

I have a frequency distribution I am trying to plot in R. The dataset is quite noisy however and results in an untidy plot.

I would like to take the mean of 10 unit sliding windows and plot that data instead. Hopefully this will clean up the plot, by reducing the number of data points?

I have tried scatter.smooth() and loess(), but these don't do what I want. I could code this myself, but wondered if anyone was aware of a function that might save the time?

Foi útil?

Solução

I found this whilst continuing my search on Google - This appears to solve my problem :D

https://stats.stackexchange.com/questions/3051/mean-of-a-sliding-window-in-r

Edit:

I'm using the following

library(zoo)
quartz()
plot(rollmean(freq_dist, 10))

Works like a dream :-D

I did an install.packages("zoo", dependencies=TRUE) in order to get the zoo library into R!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top