I have the following dataset:
require(xts)
days<-seq(as.Date("2016-05-01", format="%Y-%m-%d"), as.Date("2016-07-31", format="%Y-%m-%d" ), by= 1)
df.days<-xts(x = data.frame(Empty=rep(NA, length(days))), order.by=days)
df.norm <- rnorm(10000, 40, 5)
df.norm <- df.norm[df.norm > 30 & df.norm < 50]
SAMPLE <-sample(df.norm, length(df.days[.indexwday(df.days)==1]), replace=FALSE)
df.weeks<-xts(SAMPLE, order.by = index(df.days[.indexwday(df.days)==1]))
df.data<-merge.xts(df.weeks,df.days)
df.data<-df.data[,1]
colnames(df.data)[1]<-"rate1"
df.data<-as.data.frame(df.data)
rownames(df.data)<-NULL
df.data<-data.frame(times=rownames(df.data), coredata(df.data))
rate1 is a time-dependent function tends to approach value 40 over days.
I want to know at what date the rate1 will be equal to 40.
One possibility to do what I require is to densely populate rate1 and subtract my target value (40). The closer a point is to zero, the closer it is to the target value. And include a small 'noise' buffer, accepting all points within some range of zero.
How do I estimate times value for rate1 equal to 40 in R? Also please suggest if there is more appropriate method in R than what I am using? All suggestions are welcome.