library(tidyverse)
data("starwars", package = "dplyr")Spring 2026 | Data 2 (399)
Jeffrey M. Girard | Lecture 04c
Rows: 87
Columns: 14
$ name <chr> "Luke Skywalker", "C-3PO", "R2-D2", "Darth Vader", "Leia Or…
$ height <int> 172, 167, 96, 202, 150, 178, 165, 97, 183, 182, 188, 180, 2…
$ mass <dbl> 77.0, 75.0, 32.0, 136.0, 49.0, 120.0, 75.0, 32.0, 84.0, 77.…
$ hair_color <chr> "blond", NA, NA, "none", "brown", "brown, grey", "brown", N…
$ skin_color <chr> "fair", "gold", "white, blue", "white", "light", "light", "…
$ eye_color <chr> "blue", "yellow", "red", "yellow", "brown", "blue", "blue",…
$ birth_year <dbl> 19.0, 112.0, 33.0, 41.9, 19.0, 52.0, 47.0, NA, 24.0, 57.0, …
$ sex <chr> "male", "none", "none", "male", "female", "male", "female",…
$ gender <chr> "masculine", "masculine", "masculine", "masculine", "femini…
$ homeworld <chr> "Tatooine", "Tatooine", "Naboo", "Tatooine", "Alderaan", "T…
$ species <chr> "Human", "Droid", "Droid", "Human", "Human", "Human", "Huma…
$ films <list> <"A New Hope", "The Empire Strikes Back", "Return of the J…
$ vehicles <list> <"Snowspeeder", "Imperial Speeder Bike">, <>, <>, <>, "Imp…
$ starships <list> <"X-wing", "Imperial shuttle">, <>, <>, "TIE Advanced x1",…
Use the pipe (|>) to efficiently pass an object to a function
Build a pipeline by connecting multiple pipes together
x and then square root it|> for you%>% which is similar but requires tidyverse to be loaded# A tibble: 87 × 3
name species homeworld
<chr> <chr> <chr>
1 Luke Skywalker Human Tatooine
2 C-3PO Droid Tatooine
3 R2-D2 Droid Naboo
4 Darth Vader Human Tatooine
5 Leia Organa Human Alderaan
# ℹ 82 more rows
Formatting Tip:
Add a line break after each pipe |> and then indent the next line. RStudio will do this automatically.
Intermediate Assignment
[1] 3.321928
# A tibble: 12 × 4
name bmi mass height
<chr> <dbl> <dbl> <int>
1 Jabba Desilijic Tiure 443. 1358 175
2 Dud Bolt 50.9 45 94
3 Yoda 39.0 17 66
4 Owen Lars 37.9 120 178
5 IG-88 35 140 200
# ℹ 7 more rows
# A tibble: 7 × 3
name species height_cm
<chr> <chr> <int>
1 R2-D2 Droid 96
2 R5-D4 Droid 97
3 Yoda Yoda's species 66
4 Wicket Systri Warrick Ewok 88
5 Ratts Tyerel Aleena 79
# ℹ 2 more rows