Skip to content

Instantly share code, notes, and snippets.

@juliangehring
Created March 5, 2015 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliangehring/2046709b2d1007d72054 to your computer and use it in GitHub Desktop.
Save juliangehring/2046709b2d1007d72054 to your computer and use it in GitHub Desktop.
R sequences
## 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