[R] difficult to find index value

Ista Zahn istazahn at gmail.com
Wed Mar 30 19:21:05 CEST 2016


FAQ 7.31 I think. Here are a couple things you can try.

close_enough <- function(x, y) isTRUE(all.equal(x, y))

periodlimint<-seq(from=0.1, to=50, by=0.1)

indexAtest <- which(sapply(periodlimint, close_enough, y = 0.7))

match( as.character(.7), periodlimint)

Best,
Ista

On Wed, Mar 30, 2016 at 1:35 AM, Rubel Das via R-help
<r-help at r-project.org> wrote:
>  Dear R group memberI tried couple of hours to figure out the solution of following.match function behaves strange from value 0.7 and 1.7
>
>> periodlimint<-seq(from=0.1, to=50, by=0.1)> indexAtest<-match( .6, periodlimint)> indexAtest[1] 6> periodlimint<-seq(from=0.1, to=50, by=0.1)> indexAtest<-match( .7, periodlimint)> indexAtest[1] NA> periodlimint<-seq(from=0.1, to=50, by=0.1)> indexAtest<-match( .8, periodlimint)> indexAtest[1] 8> periodlimint<-seq(from=0.1, to=50, by=0.1)> indexAtest<-match( 1.7, periodlimint)> indexAtest[1] NA
> it will be helpful if you provide your comment
> RegardsRubel
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list