Created
March 5, 2015 08:35
-
-
Save juliangehring/2046709b2d1007d72054 to your computer and use it in GitHub Desktop.
R sequences
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## let's create a sequence, and look at the 10th element which is 0.1 | |
s1 = (1:100)/100 | |
s1[10] ## -> 0.1 | |
s1[10] == 0.1 ## -> TRUE, makes sense | |
s2 = seq(0.01, 1, by = 0.01) ## should be the same as 's1' | |
all.equal(s1, s2) ## -> TRUE, still looks good | |
identical(s1, s2) ## -> FALSE, a bit worrisome | |
s2[10] ## -> 0.1 | |
s2[10] == 0.1 ## -> FALSE, bad | |
## where this becomes important | |
sum(s1 < 0.1) ## -> 9, which is correct | |
sum(s2 < 0.1) ## -> 10, which is wrong given the definition of the sequence |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment