0

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.

abs(f[t]-\Theta)\leq \epsilon

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.

Community
  • 1
  • 1
runjumpfly
  • 319
  • 1
  • 10
  • Since `variable1` is a `float`, checking equality for such numbers will be cumbersome. I would suggest to define an appropriate tolerance i.e. `tolerance=1e-6` and check `abs(variable1-tolerance) < tolerance`. See these for more on floating point issues : [here](http://stackoverflow.com/questions/9508518/why-are-these-numbers-not-equal) and [here](http://stackoverflow.com/questions/2769510/numeric-comparison-difficulty-in-r) – Silence Dogood Nov 07 '16 at 12:44
  • @Osssan please edit my question as per your suggestions. – runjumpfly Nov 07 '16 at 12:48
  • Sorry, the check should be `targetValue = 40; abs(variable1 - targetValue ) < tolerance`, – Silence Dogood Nov 07 '16 at 13:01

0 Answers0