[R] indexing operation based upon a sequence

Berend Hasselman bhh at xs4all.nl
Thu Feb 7 18:46:08 CET 2013


R-FAQ 7.31

Berend

On 07-02-2013, at 17:41, "J. Braeken" <J.Braeken at uvt.nl> wrote:

> Dear R-list,
> 
> 
> We stumbled upon some weird problem when performing a simple indexing operation.
> Below some example code to illustrate the issue
> 
> #FAILS TO FIND .55 Oo
> huh1 = seq(.1,.7,.15);huh1
> # [1] 0.10 0.25 0.40 0.55 0.70
> huh1 == .25
> # [1] FALSE  TRUE FALSE FALSE FALSE
> huh1 == .55
> # [1] FALSE FALSE FALSE FALSE FALSE
> huh1 == "0.55"
> # [1] FALSE FALSE FALSE  TRUE FALSE
> 
> Hence somehow one element in the sequence has become a character?
> 
> #DOES NOT FAIL TO FIND .55
> huh2 = c(.1,.25,.4,.55,.7);huh3
> # [1] 0.10 0.25 0.40 0.55 0.70
> huh2 == .25
> # FALSE  TRUE FALSE FALSE FALSE
> huh2 == .55
> # [1] FALSE FALSE FALSE  TRUE FALSE
> 
> This is what you would expect.
> 
> #DOES NOT FAIL TO FIND .55 
> huh3 = seq(.1,.7,.05);huh2
> # [1] 0.10 0.25 0.40 0.55 0.70
> huh3 == .25
> # [1] FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
> huh3 == .55
> # [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE
> 
> Strangely when making a longer sequence, the weird behavior does not persist.
> 
> 
> Does anyone have a clue what is going on here?
> 
> 
>               _                            
> platform       i386-pc-mingw32              
> version.string R version 2.12.1 (2010-12-16)
> 
> 
> Best regards,
> 
> 
> Johan
> 
> ______________________________________________
> R-help at r-project.org mailing list
> 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