Created
September 18, 2014 05:32
-
-
Save johnmyleswhite/3dc3108d2b4b527a8468 to your computer and use it in GitHub Desktop.
R indexing showcases all possible design theories
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
> v <- c(1, 2, 3, 4) | |
> v[1] | |
[1] 1 | |
> v[4] | |
[1] 4 | |
> v[0] | |
numeric(0) | |
> v[5] | |
[1] NA | |
> v[-1] | |
[1] 2 3 4 | |
> v[NA] | |
[1] NA NA NA NA | |
> v[-NA] | |
[1] NA | |
> v[NULL] | |
numeric(0) | |
> v[-NULL] | |
Error in -NULL : invalid argument to unary operator |
shoestringpsycholing
commented
Sep 20, 2014
> v[Inf]
[1] NA
> v[-Inf]
[1] NA
> v[NaN]
[1] NA
> v[v]
[1] 1 2 3 4
> v[2*v]
[1] 2 4 NA NA
> v[-v]
numeric(0)
# same as v[3]
> v[pi]
[1] 3
> pi
[1] 3.141593
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment