Sequences and ordering in R
Generating and reordering regular vectors.
ones_to_ten <- 1:10
evens <- seq(2, 20, by = 2)
grid <- seq(0, 1, length.out = 5)
thrice <- rep(c("a", "b"), times = 3)
each_twice <- rep(1:3, each = 2)
reversed <- rev(ones_to_ten)
sorted <- sort(c(3, 1, 2), decreasing = TRUE)
positions <- order(c(30, 10, 20))
How it works
1:10andseqbuild ranges by step or length.reprepeats values,timesoreach.sortreorders values;orderreturns positions.
Keywords and builtins used here
corderreprevseqsort
The run, in numbers
- Lines
- 10
- Characters to type
- 263
- Tokens
- 94
- Three-star pace
- 80 tpm
At the three-star pace of 80 tokens a minute, this run takes about 70 seconds.
Step 3 of 4 in Vectors & types, step 3 of 20 in Language basics.