Skip to content
Prev 315834 / 398502 Next

Help with interpolation

Next time please provide sample data in a form we can easily read in (look at ?dput for example)

If i understand this right:

yourData<-read.table(header=T,text="
date			days  rate
1996_01_02      15    5.74590
1996_01_02      50    5.67332
1996_01_02      78    5.60888
1996_01_02     169    5.47376
1996_01_02     260    5.35267
1996_01_02     351    5.27619

1996_01_03      14    5.74740
1996_01_03      49    5.67226
1996_01_03      77    5.60371
1996_01_03     168    5.47058
1996_01_03     259    5.34662
1996_01_03     350    5.26630
")

results<-sapply(unique(yourData$date),function(thisDate){
			subSet <- yourData[yourData$date==thisDate,]
			appr<-approx(subSet$days,subSet$rate,xout=seq(0,360, by=30))
			rates<-appr$y
			names(rates)<-appr$x
			rates
		})
colnames(results)<-unique(yourData$date)

This gives 13 results per date though, and it can't interpolate the first and last value. If you need those values that are not in-between, try spline instead of approx (you never specified how you wanted to interpolate).
On 17.01.2013, at 15:50, beanbandit wrote: