[1] -0.005341163
2025-09-22
geom_density, geom_histogram, geom_freqpoly)geom_bar, geom_point with stat="count")geom_point, geom_hex, geom_contourgeom_density_ridges, geom_boplot, geom_violinfill), use facets
TRUE and FALSE!TRUE = FALSE, !FALSE=TRUETRUE & TRUE = TRUE rest FALSEFALSE | FALSE = FALSE rest TRUEComparison statements don’t work like in English:
library(kableExtra)
nycflights13::flights |> select(year,month,day,arr_delay,carrier,origin,dest) |> head(10) |> kable()| year | month | day | arr_delay | carrier | origin | dest |
|---|---|---|---|---|---|---|
| 2013 | 1 | 1 | 11 | UA | EWR | IAH |
| 2013 | 1 | 1 | 20 | UA | LGA | IAH |
| 2013 | 1 | 1 | 33 | AA | JFK | MIA |
| 2013 | 1 | 1 | -18 | B6 | JFK | BQN |
| 2013 | 1 | 1 | -25 | DL | LGA | ATL |
| 2013 | 1 | 1 | 12 | UA | EWR | ORD |
| 2013 | 1 | 1 | 19 | B6 | EWR | FLL |
| 2013 | 1 | 1 | -14 | EV | LGA | IAD |
| 2013 | 1 | 1 | -8 | B6 | JFK | MCO |
| 2013 | 1 | 1 | 8 | AA | LGA | ORD |
TRUE when airline is in the groupFALSE otherwiseflights = nycflights13::flights |>
mutate(IS_CARRIER_DL_UA_AA = carrier %in% c("DL","UA","AA"))
flights |>
group_by(IS_CARRIER_DL_UA_AA) |>
summarise(fraction_delayed = sum(arr_delay>30,na.rm=TRUE)/
sum(is.finite(arr_delay),na.rm=TRUE)) |>
print()# A tibble: 2 × 2
IS_CARRIER_DL_UA_AA fraction_delayed
<lgl> <dbl>
1 FALSE 0.180
2 TRUE 0.125
if_else and case_when: vector output[] for other data types# A tibble: 768 × 9
Pregnancies Glucose BloodPressure SkinThickness Insulin BMI
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 6 148 72 35 0 33.6
2 1 85 66 29 0 26.6
3 8 183 64 0 0 23.3
4 1 89 66 23 94 28.1
5 0 137 40 35 168 43.1
6 5 116 74 0 0 25.6
7 3 78 50 32 88 31
8 10 115 0 0 0 35.3
9 2 197 70 45 543 30.5
10 8 125 96 0 0 0
# ℹ 758 more rows
# ℹ 3 more variables: DiabetesPedigreeFunction <dbl>, Age <dbl>, Outcome <dbl>
[] for other data types# A tibble: 768 × 9
Pregnancies Glucose BloodPressure SkinThickness Insulin BMI
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 6 148 72 35 NA 33.6
2 1 85 66 29 NA 26.6
3 8 183 64 NA NA 23.3
4 1 89 66 23 94 28.1
5 0 137 40 35 168 43.1
6 5 116 74 NA NA 25.6
7 3 78 50 32 88 31
8 10 115 NA NA NA 35.3
9 2 197 70 45 543 30.5
10 8 125 96 NA NA NA
# ℹ 758 more rows
# ℹ 3 more variables: DiabetesPedigreeFunction <dbl>, Age <dbl>, Outcome <dbl>
# A tibble: 5 × 3
year month flight
<int> <int> <int>
1 2013 1 1545
2 2013 1 1141
3 2013 1 461
4 2013 1 507
5 2013 1 79
# A tibble: 5 × 3
year month flight
<int> <int> <int>
1 2013 1 1545
2 2013 1 1714
3 2013 1 1141
4 2013 1 725
5 2013 1 461
log likelihoodlead Next value(s)lag Previous value(s) [1] 2 3 4 5 6 7 8 9 10 NA
[1] 4 5 6 7 8 9 10 NA NA NA
[1] NA 1 2 3 4 5 6 7 8 9
[1] NA NA NA 1 2 3 4 5 6 7
first() and last()percent_rank()rank()ntile()cumsum, cummeanRcppRoll, TTR, slider)cumsum, cummeanRcppRoll, TTR, slider)rank transforms data from values to numerical rank: [1] 2.3018724 0.4560994 0.8971370 1.2285259 -0.5153130 -0.4754930
[7] -1.0822176 1.7008024 -0.1618288 0.2311937
[1] 10 6 7 8 2 3 1 9 4 5
rank_corr corr
1 0.7162994 -0.005341163
logit, probit, ReLU: Data transformations that go between a finite interval and the real linePlease fill out the following google form after the meeting or watching the video: