#> [1] 1.1 2.2 3.3 4.4
#> [1] 4.4 1.1
#> [1] 1.1 1.1 1.1
#> [1] 1.1
[
[[
and $
#> [1] 1.1 2.2 3.3 4.4
#> [1] 4.4 1.1
#> [1] 1.1 1.1 1.1
#> [1] 1.1
Reals truncate to integers.
#> numeric(0)
#> [1] 1.1 2.2 3.3 4.4
#> [1] 2.2 4.4
[
[
returns a list#> $a
#> [1] TRUE FALSE
#>
#> $b
#> [1] "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o"
#>
#> $c
#> [1] 100 101 102 103 104 105 106 107 108
#> $a
#> [1] TRUE FALSE
#>
#> $b
#> [1] "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o"
[
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] "1,1" "1,2" "1,3" "1,4" "1,5"
#> [2,] "2,1" "2,2" "2,3" "2,4" "2,5"
#> [3,] "3,1" "3,2" "3,3" "3,4" "3,5"
#> [4,] "4,1" "4,2" "4,3" "4,4" "4,5"
#> [5,] "5,1" "5,2" "5,3" "5,4" "5,5"
#> [1] "4,1" "5,3"
#> [1] 6 7 8 9
[
returns a tibble[[
selects a single element$
is shorthand for [[..., exact = FALSE]]
purrr::pluck()
and purrr::chuck()
provide consistent wrapperspurrr::pluck()
always returns NULL
or .default
for (non-NULL
) missingpurrr::chuck()
always throws error@
equivalent to $
(but error if bad)slot()
equivalent to [[
More in Chapter 15
[
NULL
list(NULL)
to add NULL
order()
Ideally a future cohort should expand these:
setdiff()
df[df$col > 5, ]
which()
which()
gives the indices of a Boolean vector(x1 <- 1:10 %% 2 == 0) # 1-10 divisible by 2
# [1] FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE
(x2 <- which(x1))
# [1] 2 4 6 8 10
(y1 <- 1:10 %% 5 == 0) # 1-10 divisible by 5
# [1] FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE TRUE
(y2 <- which(y1))
# [1] 5 10
x1 & y1
# [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE