Depending on your actual data and how you want to smooth it, and why you want to smooth it, there are various options.
I show you examples with linear regression (first and second order) and local regression (LOESS). These may or may not be good statistical models for using your data, but it's hard to say without seeing it. Anyway:
time <- 0:100 temp <- 20+ 0.01 * time^2 + 0.8 * time + rnorm(101, 0, 5) # Generate first order linear model lin.mod <- lm(temp~time) # Generate second order linear model lin.mod2 <- lm(temp~I(time^2)+time) # Calculate local regression ls <- loess(temp~time) # Predict the data (passing only the model runs the prediction # on the data points used to generate the model itself) pr.lm <- predict(lin.mod) pr.lm2 <- predict(lin.mod2) pr.loess <- predict(ls) par(mfrow=c(2,2)) plot(time, temp, "l", las=1, xlab="Time", ylab="Temperature") lines(pr.lm~time, col="blue", lwd=2) plot(time, temp, "l", las=1, xlab="Time", ylab="Temperature") lines(pr.lm2~time, col="green", lwd=2) plot(time, temp, "l", las=1, xlab="Time", ylab="Temperature") lines(pr.loess~time, col="red", lwd=2)
Another option is to use a moving average.
For instance:
library(zoo) mov.avg <- rollmean(temp, 5, fill=NA) plot(time, temp, "l") lines(time, mov.avg, col="orange", lwd=2)
