I am a beginner in curve fitting and several posts on Stackoverflow really helped me.
I tried to fit a sine curve to my data using lm
and nls
Alternatively, you could have eliminated the NAs from your data after reading it in:
data <- subset(data, !is.na(temperature))
Then, when plotting, you could set the x-axis to the time points from the reduced data set:
plot(temp~time, data=data, xlim=c(1, 900))
lines(x=time, y=fit.lm$fitted, col="red")
This curve won't be as smooth as the one produced by @andy-barbour but it will work in a pinch.