October 26, 2017
Code with a lot of duplication is harder to understand, troubleshoot and maintain. The goal of this tutorial is help you remove duplication in your code by using functions that write for loops for you.
You'll learn to use the functions in the purrr package to perform iterative tasks: tasks that look like "for each _____ do _____".
The goal is to make strides towards writing code that is more readable and easier to update and so that you are ready to solve new iteration problems faster and with fewer mistakes.
You might already be solving problems purrr addresses with copy&paste, for loops, functions of the apply family, etc.
An alternative is using purrr::map() and friends.
By the end of the workshop, you'll be able to:
map().# purrr + dplyr + ... library(tidyverse) # includes: sw_films, sw_people, sw_vehicles, # sw_starships, sw_planets & sw_species library(repurrrsive)
The goal of a function should be to encapsulate a small reusable piece of code.
Name should make it clear what the function does (think in terms of simple verbs).
Functionality should be simple enough to be quickly understood.
The smaller and more modular the code the easier it will be to reuse elsewhere.
Better to change code in one location than code everywhere.
In R functions are first order objects, this means we can work with them like any other object in R.
f = function(x) x*x typeof(f)
## [1] "closure"
list(f)
## [[1]] ## function (x) ## x * x
g = f g(3)
## [1] 9
{function(x) x*x*x}(3)
## [1] 27
The two parts of a function are the arguments (formals) and the code (body).
gcd = function(loc1, loc2)
{
deg2rad = function(deg) return(deg*pi/180)
lat1 = deg2rad( loc1[1] )
lat2 = deg2rad( loc2[1] )
long1 = deg2rad( loc1[2] )
long2 = deg2rad( loc2[2] )
R = 6371 # Earth mean radius in km
d = acos(sin(lat1)*sin(lat2) + cos(lat1)*cos(lat2) * cos(long2-long1)) * R
return(d) # distance in km
}
formals(gcd)
## $loc1 ## ## ## $loc2
body(gcd)
## {
## deg2rad = function(deg) return(deg * pi/180)
## lat1 = deg2rad(loc1[1])
## lat2 = deg2rad(loc2[1])
## long1 = deg2rad(loc1[2])
## long2 = deg2rad(loc2[2])
## R = 6371
## d = acos(sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) *
## cos(long2 - long1)) * R
## return(d)
## }
A tidyverse package which improves functional programming in R with a focus on pure and type stable functions.
typeof(sw_people)
## [1] "list"
str(sw_people)
## List of 87 ## $ :List of 16 ## ..$ name : chr "Luke Skywalker" ## ..$ height : chr "172" ## ..$ mass : chr "77" ## ..$ hair_color: chr "blond" ## ..$ skin_color: chr "fair" ## ..$ eye_color : chr "blue" ## ..$ birth_year: chr "19BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/1/" ## ..$ films : chr [1:5] "http://swapi.co/api/films/6/" "http://swapi.co/api/films/3/" "http://swapi.co/api/films/2/" "http://swapi.co/api/films/1/" ... ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ vehicles : chr [1:2] "http://swapi.co/api/vehicles/14/" "http://swapi.co/api/vehicles/30/" ## ..$ starships : chr [1:2] "http://swapi.co/api/starships/12/" "http://swapi.co/api/starships/22/" ## ..$ created : chr "2014-12-09T13:50:51.644000Z" ## ..$ edited : chr "2014-12-20T21:17:56.891000Z" ## ..$ url : chr "http://swapi.co/api/people/1/" ## $ :List of 14 ## ..$ name : chr "C-3PO" ## ..$ height : chr "167" ## ..$ mass : chr "75" ## ..$ hair_color: chr "n/a" ## ..$ skin_color: chr "gold" ## ..$ eye_color : chr "yellow" ## ..$ birth_year: chr "112BBY" ## ..$ gender : chr "n/a" ## ..$ homeworld : chr "http://swapi.co/api/planets/1/" ## ..$ films : chr [1:6] "http://swapi.co/api/films/5/" "http://swapi.co/api/films/4/" "http://swapi.co/api/films/6/" "http://swapi.co/api/films/3/" ... ## ..$ species : chr "http://swapi.co/api/species/2/" ## ..$ created : chr "2014-12-10T15:10:51.357000Z" ## ..$ edited : chr "2014-12-20T21:17:50.309000Z" ## ..$ url : chr "http://swapi.co/api/people/2/" ## $ :List of 14 ## ..$ name : chr "R2-D2" ## ..$ height : chr "96" ## ..$ mass : chr "32" ## ..$ hair_color: chr "n/a" ## ..$ skin_color: chr "white, blue" ## ..$ eye_color : chr "red" ## ..$ birth_year: chr "33BBY" ## ..$ gender : chr "n/a" ## ..$ homeworld : chr "http://swapi.co/api/planets/8/" ## ..$ films : chr [1:7] "http://swapi.co/api/films/5/" "http://swapi.co/api/films/4/" "http://swapi.co/api/films/6/" "http://swapi.co/api/films/3/" ... ## ..$ species : chr "http://swapi.co/api/species/2/" ## ..$ created : chr "2014-12-10T15:11:50.376000Z" ## ..$ edited : chr "2014-12-20T21:17:50.311000Z" ## ..$ url : chr "http://swapi.co/api/people/3/" ## $ :List of 15 ## ..$ name : chr "Darth Vader" ## ..$ height : chr "202" ## ..$ mass : chr "136" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "white" ## ..$ eye_color : chr "yellow" ## ..$ birth_year: chr "41.9BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/1/" ## ..$ films : chr [1:4] "http://swapi.co/api/films/6/" "http://swapi.co/api/films/3/" "http://swapi.co/api/films/2/" "http://swapi.co/api/films/1/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ starships : chr "http://swapi.co/api/starships/13/" ## ..$ created : chr "2014-12-10T15:18:20.704000Z" ## ..$ edited : chr "2014-12-20T21:17:50.313000Z" ## ..$ url : chr "http://swapi.co/api/people/4/" ## $ :List of 15 ## ..$ name : chr "Leia Organa" ## ..$ height : chr "150" ## ..$ mass : chr "49" ## ..$ hair_color: chr "brown" ## ..$ skin_color: chr "light" ## ..$ eye_color : chr "brown" ## ..$ birth_year: chr "19BBY" ## ..$ gender : chr "female" ## ..$ homeworld : chr "http://swapi.co/api/planets/2/" ## ..$ films : chr [1:5] "http://swapi.co/api/films/6/" "http://swapi.co/api/films/3/" "http://swapi.co/api/films/2/" "http://swapi.co/api/films/1/" ... ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ vehicles : chr "http://swapi.co/api/vehicles/30/" ## ..$ created : chr "2014-12-10T15:20:09.791000Z" ## ..$ edited : chr "2014-12-20T21:17:50.315000Z" ## ..$ url : chr "http://swapi.co/api/people/5/" ## $ :List of 14 ## ..$ name : chr "Owen Lars" ## ..$ height : chr "178" ## ..$ mass : chr "120" ## ..$ hair_color: chr "brown, grey" ## ..$ skin_color: chr "light" ## ..$ eye_color : chr "blue" ## ..$ birth_year: chr "52BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/1/" ## ..$ films : chr [1:3] "http://swapi.co/api/films/5/" "http://swapi.co/api/films/6/" "http://swapi.co/api/films/1/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ created : chr "2014-12-10T15:52:14.024000Z" ## ..$ edited : chr "2014-12-20T21:17:50.317000Z" ## ..$ url : chr "http://swapi.co/api/people/6/" ## $ :List of 14 ## ..$ name : chr "Beru Whitesun lars" ## ..$ height : chr "165" ## ..$ mass : chr "75" ## ..$ hair_color: chr "brown" ## ..$ skin_color: chr "light" ## ..$ eye_color : chr "blue" ## ..$ birth_year: chr "47BBY" ## ..$ gender : chr "female" ## ..$ homeworld : chr "http://swapi.co/api/planets/1/" ## ..$ films : chr [1:3] "http://swapi.co/api/films/5/" "http://swapi.co/api/films/6/" "http://swapi.co/api/films/1/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ created : chr "2014-12-10T15:53:41.121000Z" ## ..$ edited : chr "2014-12-20T21:17:50.319000Z" ## ..$ url : chr "http://swapi.co/api/people/7/" ## $ :List of 14 ## ..$ name : chr "R5-D4" ## ..$ height : chr "97" ## ..$ mass : chr "32" ## ..$ hair_color: chr "n/a" ## ..$ skin_color: chr "white, red" ## ..$ eye_color : chr "red" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "n/a" ## ..$ homeworld : chr "http://swapi.co/api/planets/1/" ## ..$ films : chr "http://swapi.co/api/films/1/" ## ..$ species : chr "http://swapi.co/api/species/2/" ## ..$ created : chr "2014-12-10T15:57:50.959000Z" ## ..$ edited : chr "2014-12-20T21:17:50.321000Z" ## ..$ url : chr "http://swapi.co/api/people/8/" ## $ :List of 15 ## ..$ name : chr "Biggs Darklighter" ## ..$ height : chr "183" ## ..$ mass : chr "84" ## ..$ hair_color: chr "black" ## ..$ skin_color: chr "light" ## ..$ eye_color : chr "brown" ## ..$ birth_year: chr "24BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/1/" ## ..$ films : chr "http://swapi.co/api/films/1/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ starships : chr "http://swapi.co/api/starships/12/" ## ..$ created : chr "2014-12-10T15:59:50.509000Z" ## ..$ edited : chr "2014-12-20T21:17:50.323000Z" ## ..$ url : chr "http://swapi.co/api/people/9/" ## $ :List of 16 ## ..$ name : chr "Obi-Wan Kenobi" ## ..$ height : chr "182" ## ..$ mass : chr "77" ## ..$ hair_color: chr "auburn, white" ## ..$ skin_color: chr "fair" ## ..$ eye_color : chr "blue-gray" ## ..$ birth_year: chr "57BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/20/" ## ..$ films : chr [1:6] "http://swapi.co/api/films/5/" "http://swapi.co/api/films/4/" "http://swapi.co/api/films/6/" "http://swapi.co/api/films/3/" ... ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ vehicles : chr "http://swapi.co/api/vehicles/38/" ## ..$ starships : chr [1:5] "http://swapi.co/api/starships/48/" "http://swapi.co/api/starships/59/" "http://swapi.co/api/starships/64/" "http://swapi.co/api/starships/65/" ... ## ..$ created : chr "2014-12-10T16:16:29.192000Z" ## ..$ edited : chr "2014-12-20T21:17:50.325000Z" ## ..$ url : chr "http://swapi.co/api/people/10/" ## $ :List of 16 ## ..$ name : chr "Anakin Skywalker" ## ..$ height : chr "188" ## ..$ mass : chr "84" ## ..$ hair_color: chr "blond" ## ..$ skin_color: chr "fair" ## ..$ eye_color : chr "blue" ## ..$ birth_year: chr "41.9BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/1/" ## ..$ films : chr [1:3] "http://swapi.co/api/films/5/" "http://swapi.co/api/films/4/" "http://swapi.co/api/films/6/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ vehicles : chr [1:2] "http://swapi.co/api/vehicles/44/" "http://swapi.co/api/vehicles/46/" ## ..$ starships : chr [1:3] "http://swapi.co/api/starships/59/" "http://swapi.co/api/starships/65/" "http://swapi.co/api/starships/39/" ## ..$ created : chr "2014-12-10T16:20:44.310000Z" ## ..$ edited : chr "2014-12-20T21:17:50.327000Z" ## ..$ url : chr "http://swapi.co/api/people/11/" ## $ :List of 14 ## ..$ name : chr "Wilhuff Tarkin" ## ..$ height : chr "180" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "auburn, grey" ## ..$ skin_color: chr "fair" ## ..$ eye_color : chr "blue" ## ..$ birth_year: chr "64BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/21/" ## ..$ films : chr [1:2] "http://swapi.co/api/films/6/" "http://swapi.co/api/films/1/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ created : chr "2014-12-10T16:26:56.138000Z" ## ..$ edited : chr "2014-12-20T21:17:50.330000Z" ## ..$ url : chr "http://swapi.co/api/people/12/" ## $ :List of 16 ## ..$ name : chr "Chewbacca" ## ..$ height : chr "228" ## ..$ mass : chr "112" ## ..$ hair_color: chr "brown" ## ..$ skin_color: chr "unknown" ## ..$ eye_color : chr "blue" ## ..$ birth_year: chr "200BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/14/" ## ..$ films : chr [1:5] "http://swapi.co/api/films/6/" "http://swapi.co/api/films/3/" "http://swapi.co/api/films/2/" "http://swapi.co/api/films/1/" ... ## ..$ species : chr "http://swapi.co/api/species/3/" ## ..$ vehicles : chr "http://swapi.co/api/vehicles/19/" ## ..$ starships : chr [1:2] "http://swapi.co/api/starships/10/" "http://swapi.co/api/starships/22/" ## ..$ created : chr "2014-12-10T16:42:45.066000Z" ## ..$ edited : chr "2014-12-20T21:17:50.332000Z" ## ..$ url : chr "http://swapi.co/api/people/13/" ## $ :List of 15 ## ..$ name : chr "Han Solo" ## ..$ height : chr "180" ## ..$ mass : chr "80" ## ..$ hair_color: chr "brown" ## ..$ skin_color: chr "fair" ## ..$ eye_color : chr "brown" ## ..$ birth_year: chr "29BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/22/" ## ..$ films : chr [1:4] "http://swapi.co/api/films/3/" "http://swapi.co/api/films/2/" "http://swapi.co/api/films/1/" "http://swapi.co/api/films/7/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ starships : chr [1:2] "http://swapi.co/api/starships/10/" "http://swapi.co/api/starships/22/" ## ..$ created : chr "2014-12-10T16:49:14.582000Z" ## ..$ edited : chr "2014-12-20T21:17:50.334000Z" ## ..$ url : chr "http://swapi.co/api/people/14/" ## $ :List of 14 ## ..$ name : chr "Greedo" ## ..$ height : chr "173" ## ..$ mass : chr "74" ## ..$ hair_color: chr "n/a" ## ..$ skin_color: chr "green" ## ..$ eye_color : chr "black" ## ..$ birth_year: chr "44BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/23/" ## ..$ films : chr "http://swapi.co/api/films/1/" ## ..$ species : chr "http://swapi.co/api/species/4/" ## ..$ created : chr "2014-12-10T17:03:30.334000Z" ## ..$ edited : chr "2014-12-20T21:17:50.336000Z" ## ..$ url : chr "http://swapi.co/api/people/15/" ## $ :List of 14 ## ..$ name : chr "Jabba Desilijic Tiure" ## ..$ height : chr "175" ## ..$ mass : chr "1,358" ## ..$ hair_color: chr "n/a" ## ..$ skin_color: chr "green-tan, brown" ## ..$ eye_color : chr "orange" ## ..$ birth_year: chr "600BBY" ## ..$ gender : chr "hermaphrodite" ## ..$ homeworld : chr "http://swapi.co/api/planets/24/" ## ..$ films : chr [1:3] "http://swapi.co/api/films/4/" "http://swapi.co/api/films/3/" "http://swapi.co/api/films/1/" ## ..$ species : chr "http://swapi.co/api/species/5/" ## ..$ created : chr "2014-12-10T17:11:31.638000Z" ## ..$ edited : chr "2014-12-20T21:17:50.338000Z" ## ..$ url : chr "http://swapi.co/api/people/16/" ## $ :List of 16 ## ..$ name : chr "Wedge Antilles" ## ..$ height : chr "170" ## ..$ mass : chr "77" ## ..$ hair_color: chr "brown" ## ..$ skin_color: chr "fair" ## ..$ eye_color : chr "hazel" ## ..$ birth_year: chr "21BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/22/" ## ..$ films : chr [1:3] "http://swapi.co/api/films/3/" "http://swapi.co/api/films/2/" "http://swapi.co/api/films/1/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ vehicles : chr "http://swapi.co/api/vehicles/14/" ## ..$ starships : chr "http://swapi.co/api/starships/12/" ## ..$ created : chr "2014-12-12T11:08:06.469000Z" ## ..$ edited : chr "2014-12-20T21:17:50.341000Z" ## ..$ url : chr "http://swapi.co/api/people/18/" ## $ :List of 15 ## ..$ name : chr "Jek Tono Porkins" ## ..$ height : chr "180" ## ..$ mass : chr "110" ## ..$ hair_color: chr "brown" ## ..$ skin_color: chr "fair" ## ..$ eye_color : chr "blue" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/26/" ## ..$ films : chr "http://swapi.co/api/films/1/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ starships : chr "http://swapi.co/api/starships/12/" ## ..$ created : chr "2014-12-12T11:16:56.569000Z" ## ..$ edited : chr "2014-12-20T21:17:50.343000Z" ## ..$ url : chr "http://swapi.co/api/people/19/" ## $ :List of 14 ## ..$ name : chr "Yoda" ## ..$ height : chr "66" ## ..$ mass : chr "17" ## ..$ hair_color: chr "white" ## ..$ skin_color: chr "green" ## ..$ eye_color : chr "brown" ## ..$ birth_year: chr "896BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/28/" ## ..$ films : chr [1:5] "http://swapi.co/api/films/5/" "http://swapi.co/api/films/4/" "http://swapi.co/api/films/6/" "http://swapi.co/api/films/3/" ... ## ..$ species : chr "http://swapi.co/api/species/6/" ## ..$ created : chr "2014-12-15T12:26:01.042000Z" ## ..$ edited : chr "2014-12-20T21:17:50.345000Z" ## ..$ url : chr "http://swapi.co/api/people/20/" ## $ :List of 14 ## ..$ name : chr "Palpatine" ## ..$ height : chr "170" ## ..$ mass : chr "75" ## ..$ hair_color: chr "grey" ## ..$ skin_color: chr "pale" ## ..$ eye_color : chr "yellow" ## ..$ birth_year: chr "82BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/8/" ## ..$ films : chr [1:5] "http://swapi.co/api/films/5/" "http://swapi.co/api/films/4/" "http://swapi.co/api/films/6/" "http://swapi.co/api/films/3/" ... ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ created : chr "2014-12-15T12:48:05.971000Z" ## ..$ edited : chr "2014-12-20T21:17:50.347000Z" ## ..$ url : chr "http://swapi.co/api/people/21/" ## $ :List of 15 ## ..$ name : chr "Boba Fett" ## ..$ height : chr "183" ## ..$ mass : chr "78.2" ## ..$ hair_color: chr "black" ## ..$ skin_color: chr "fair" ## ..$ eye_color : chr "brown" ## ..$ birth_year: chr "31.5BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/10/" ## ..$ films : chr [1:3] "http://swapi.co/api/films/5/" "http://swapi.co/api/films/3/" "http://swapi.co/api/films/2/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ starships : chr "http://swapi.co/api/starships/21/" ## ..$ created : chr "2014-12-15T12:49:32.457000Z" ## ..$ edited : chr "2014-12-20T21:17:50.349000Z" ## ..$ url : chr "http://swapi.co/api/people/22/" ## $ :List of 14 ## ..$ name : chr "IG-88" ## ..$ height : chr "200" ## ..$ mass : chr "140" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "metal" ## ..$ eye_color : chr "red" ## ..$ birth_year: chr "15BBY" ## ..$ gender : chr "none" ## ..$ homeworld : chr "http://swapi.co/api/planets/28/" ## ..$ films : chr "http://swapi.co/api/films/2/" ## ..$ species : chr "http://swapi.co/api/species/2/" ## ..$ created : chr "2014-12-15T12:51:10.076000Z" ## ..$ edited : chr "2014-12-20T21:17:50.351000Z" ## ..$ url : chr "http://swapi.co/api/people/23/" ## $ :List of 14 ## ..$ name : chr "Bossk" ## ..$ height : chr "190" ## ..$ mass : chr "113" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "green" ## ..$ eye_color : chr "red" ## ..$ birth_year: chr "53BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/29/" ## ..$ films : chr "http://swapi.co/api/films/2/" ## ..$ species : chr "http://swapi.co/api/species/7/" ## ..$ created : chr "2014-12-15T12:53:49.297000Z" ## ..$ edited : chr "2014-12-20T21:17:50.355000Z" ## ..$ url : chr "http://swapi.co/api/people/24/" ## $ :List of 15 ## ..$ name : chr "Lando Calrissian" ## ..$ height : chr "177" ## ..$ mass : chr "79" ## ..$ hair_color: chr "black" ## ..$ skin_color: chr "dark" ## ..$ eye_color : chr "brown" ## ..$ birth_year: chr "31BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/30/" ## ..$ films : chr [1:2] "http://swapi.co/api/films/3/" "http://swapi.co/api/films/2/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ starships : chr "http://swapi.co/api/starships/10/" ## ..$ created : chr "2014-12-15T12:56:32.683000Z" ## ..$ edited : chr "2014-12-20T21:17:50.357000Z" ## ..$ url : chr "http://swapi.co/api/people/25/" ## $ :List of 14 ## ..$ name : chr "Lobot" ## ..$ height : chr "175" ## ..$ mass : chr "79" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "light" ## ..$ eye_color : chr "blue" ## ..$ birth_year: chr "37BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/6/" ## ..$ films : chr "http://swapi.co/api/films/2/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ created : chr "2014-12-15T13:01:57.178000Z" ## ..$ edited : chr "2014-12-20T21:17:50.359000Z" ## ..$ url : chr "http://swapi.co/api/people/26/" ## $ :List of 14 ## ..$ name : chr "Ackbar" ## ..$ height : chr "180" ## ..$ mass : chr "83" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "brown mottle" ## ..$ eye_color : chr "orange" ## ..$ birth_year: chr "41BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/31/" ## ..$ films : chr [1:2] "http://swapi.co/api/films/3/" "http://swapi.co/api/films/7/" ## ..$ species : chr "http://swapi.co/api/species/8/" ## ..$ created : chr "2014-12-18T11:07:50.584000Z" ## ..$ edited : chr "2014-12-20T21:17:50.362000Z" ## ..$ url : chr "http://swapi.co/api/people/27/" ## $ :List of 14 ## ..$ name : chr "Mon Mothma" ## ..$ height : chr "150" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "auburn" ## ..$ skin_color: chr "fair" ## ..$ eye_color : chr "blue" ## ..$ birth_year: chr "48BBY" ## ..$ gender : chr "female" ## ..$ homeworld : chr "http://swapi.co/api/planets/32/" ## ..$ films : chr "http://swapi.co/api/films/3/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ created : chr "2014-12-18T11:12:38.895000Z" ## ..$ edited : chr "2014-12-20T21:17:50.364000Z" ## ..$ url : chr "http://swapi.co/api/people/28/" ## $ :List of 15 ## ..$ name : chr "Arvel Crynyd" ## ..$ height : chr "unknown" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "brown" ## ..$ skin_color: chr "fair" ## ..$ eye_color : chr "brown" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/28/" ## ..$ films : chr "http://swapi.co/api/films/3/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ starships : chr "http://swapi.co/api/starships/28/" ## ..$ created : chr "2014-12-18T11:16:33.020000Z" ## ..$ edited : chr "2014-12-20T21:17:50.367000Z" ## ..$ url : chr "http://swapi.co/api/people/29/" ## $ :List of 14 ## ..$ name : chr "Wicket Systri Warrick" ## ..$ height : chr "88" ## ..$ mass : chr "20" ## ..$ hair_color: chr "brown" ## ..$ skin_color: chr "brown" ## ..$ eye_color : chr "brown" ## ..$ birth_year: chr "8BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/7/" ## ..$ films : chr "http://swapi.co/api/films/3/" ## ..$ species : chr "http://swapi.co/api/species/9/" ## ..$ created : chr "2014-12-18T11:21:58.954000Z" ## ..$ edited : chr "2014-12-20T21:17:50.369000Z" ## ..$ url : chr "http://swapi.co/api/people/30/" ## $ :List of 15 ## ..$ name : chr "Nien Nunb" ## ..$ height : chr "160" ## ..$ mass : chr "68" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "grey" ## ..$ eye_color : chr "black" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/33/" ## ..$ films : chr "http://swapi.co/api/films/3/" ## ..$ species : chr "http://swapi.co/api/species/10/" ## ..$ starships : chr "http://swapi.co/api/starships/10/" ## ..$ created : chr "2014-12-18T11:26:18.541000Z" ## ..$ edited : chr "2014-12-20T21:17:50.371000Z" ## ..$ url : chr "http://swapi.co/api/people/31/" ## $ :List of 15 ## ..$ name : chr "Qui-Gon Jinn" ## ..$ height : chr "193" ## ..$ mass : chr "89" ## ..$ hair_color: chr "brown" ## ..$ skin_color: chr "fair" ## ..$ eye_color : chr "blue" ## ..$ birth_year: chr "92BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/28/" ## ..$ films : chr "http://swapi.co/api/films/4/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ vehicles : chr "http://swapi.co/api/vehicles/38/" ## ..$ created : chr "2014-12-19T16:54:53.618000Z" ## ..$ edited : chr "2014-12-20T21:17:50.375000Z" ## ..$ url : chr "http://swapi.co/api/people/32/" ## $ :List of 14 ## ..$ name : chr "Nute Gunray" ## ..$ height : chr "191" ## ..$ mass : chr "90" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "mottled green" ## ..$ eye_color : chr "red" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/18/" ## ..$ films : chr [1:3] "http://swapi.co/api/films/5/" "http://swapi.co/api/films/4/" "http://swapi.co/api/films/6/" ## ..$ species : chr "http://swapi.co/api/species/11/" ## ..$ created : chr "2014-12-19T17:05:57.357000Z" ## ..$ edited : chr "2014-12-20T21:17:50.377000Z" ## ..$ url : chr "http://swapi.co/api/people/33/" ## $ :List of 14 ## ..$ name : chr "Finis Valorum" ## ..$ height : chr "170" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "blond" ## ..$ skin_color: chr "fair" ## ..$ eye_color : chr "blue" ## ..$ birth_year: chr "91BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/9/" ## ..$ films : chr "http://swapi.co/api/films/4/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ created : chr "2014-12-19T17:21:45.915000Z" ## ..$ edited : chr "2014-12-20T21:17:50.379000Z" ## ..$ url : chr "http://swapi.co/api/people/34/" ## $ :List of 14 ## ..$ name : chr "Jar Jar Binks" ## ..$ height : chr "196" ## ..$ mass : chr "66" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "orange" ## ..$ eye_color : chr "orange" ## ..$ birth_year: chr "52BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/8/" ## ..$ films : chr [1:2] "http://swapi.co/api/films/5/" "http://swapi.co/api/films/4/" ## ..$ species : chr "http://swapi.co/api/species/12/" ## ..$ created : chr "2014-12-19T17:29:32.489000Z" ## ..$ edited : chr "2014-12-20T21:17:50.383000Z" ## ..$ url : chr "http://swapi.co/api/people/36/" ## $ :List of 14 ## ..$ name : chr "Roos Tarpals" ## ..$ height : chr "224" ## ..$ mass : chr "82" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "grey" ## ..$ eye_color : chr "orange" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/8/" ## ..$ films : chr "http://swapi.co/api/films/4/" ## ..$ species : chr "http://swapi.co/api/species/12/" ## ..$ created : chr "2014-12-19T17:32:56.741000Z" ## ..$ edited : chr "2014-12-20T21:17:50.385000Z" ## ..$ url : chr "http://swapi.co/api/people/37/" ## $ :List of 14 ## ..$ name : chr "Rugor Nass" ## ..$ height : chr "206" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "green" ## ..$ eye_color : chr "orange" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/8/" ## ..$ films : chr "http://swapi.co/api/films/4/" ## ..$ species : chr "http://swapi.co/api/species/12/" ## ..$ created : chr "2014-12-19T17:33:38.909000Z" ## ..$ edited : chr "2014-12-20T21:17:50.388000Z" ## ..$ url : chr "http://swapi.co/api/people/38/" ## $ :List of 14 ## ..$ name : chr "Ric Olié" ## ..$ height : chr "183" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "brown" ## ..$ skin_color: chr "fair" ## ..$ eye_color : chr "blue" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/8/" ## ..$ films : chr "http://swapi.co/api/films/4/" ## ..$ starships : chr "http://swapi.co/api/starships/40/" ## ..$ created : chr "2014-12-19T17:45:01.522000Z" ## ..$ edited : chr "2014-12-20T21:17:50.392000Z" ## ..$ url : chr "http://swapi.co/api/people/39/" ## $ :List of 14 ## ..$ name : chr "Watto" ## ..$ height : chr "137" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "black" ## ..$ skin_color: chr "blue, grey" ## ..$ eye_color : chr "yellow" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/34/" ## ..$ films : chr [1:2] "http://swapi.co/api/films/5/" "http://swapi.co/api/films/4/" ## ..$ species : chr "http://swapi.co/api/species/13/" ## ..$ created : chr "2014-12-19T17:48:54.647000Z" ## ..$ edited : chr "2014-12-20T21:17:50.395000Z" ## ..$ url : chr "http://swapi.co/api/people/40/" ## $ :List of 14 ## ..$ name : chr "Sebulba" ## ..$ height : chr "112" ## ..$ mass : chr "40" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "grey, red" ## ..$ eye_color : chr "orange" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/35/" ## ..$ films : chr "http://swapi.co/api/films/4/" ## ..$ species : chr "http://swapi.co/api/species/14/" ## ..$ created : chr "2014-12-19T17:53:02.586000Z" ## ..$ edited : chr "2014-12-20T21:17:50.397000Z" ## ..$ url : chr "http://swapi.co/api/people/41/" ## $ :List of 13 ## ..$ name : chr "Quarsh Panaka" ## ..$ height : chr "183" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "black" ## ..$ skin_color: chr "dark" ## ..$ eye_color : chr "brown" ## ..$ birth_year: chr "62BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/8/" ## ..$ films : chr "http://swapi.co/api/films/4/" ## ..$ created : chr "2014-12-19T17:55:43.348000Z" ## ..$ edited : chr "2014-12-20T21:17:50.399000Z" ## ..$ url : chr "http://swapi.co/api/people/42/" ## $ :List of 14 ## ..$ name : chr "Shmi Skywalker" ## ..$ height : chr "163" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "black" ## ..$ skin_color: chr "fair" ## ..$ eye_color : chr "brown" ## ..$ birth_year: chr "72BBY" ## ..$ gender : chr "female" ## ..$ homeworld : chr "http://swapi.co/api/planets/1/" ## ..$ films : chr [1:2] "http://swapi.co/api/films/5/" "http://swapi.co/api/films/4/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ created : chr "2014-12-19T17:57:41.191000Z" ## ..$ edited : chr "2014-12-20T21:17:50.401000Z" ## ..$ url : chr "http://swapi.co/api/people/43/" ## $ :List of 16 ## ..$ name : chr "Darth Maul" ## ..$ height : chr "175" ## ..$ mass : chr "80" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "red" ## ..$ eye_color : chr "yellow" ## ..$ birth_year: chr "54BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/36/" ## ..$ films : chr "http://swapi.co/api/films/4/" ## ..$ species : chr "http://swapi.co/api/species/22/" ## ..$ vehicles : chr "http://swapi.co/api/vehicles/42/" ## ..$ starships : chr "http://swapi.co/api/starships/41/" ## ..$ created : chr "2014-12-19T18:00:41.929000Z" ## ..$ edited : chr "2014-12-20T21:17:50.403000Z" ## ..$ url : chr "http://swapi.co/api/people/44/" ## $ :List of 14 ## ..$ name : chr "Bib Fortuna" ## ..$ height : chr "180" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "pale" ## ..$ eye_color : chr "pink" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/37/" ## ..$ films : chr "http://swapi.co/api/films/3/" ## ..$ species : chr "http://swapi.co/api/species/15/" ## ..$ created : chr "2014-12-20T09:47:02.512000Z" ## ..$ edited : chr "2014-12-20T21:17:50.407000Z" ## ..$ url : chr "http://swapi.co/api/people/45/" ## $ :List of 14 ## ..$ name : chr "Ayla Secura" ## ..$ height : chr "178" ## ..$ mass : chr "55" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "blue" ## ..$ eye_color : chr "hazel" ## ..$ birth_year: chr "48BBY" ## ..$ gender : chr "female" ## ..$ homeworld : chr "http://swapi.co/api/planets/37/" ## ..$ films : chr [1:3] "http://swapi.co/api/films/5/" "http://swapi.co/api/films/4/" "http://swapi.co/api/films/6/" ## ..$ species : chr "http://swapi.co/api/species/15/" ## ..$ created : chr "2014-12-20T09:48:01.172000Z" ## ..$ edited : chr "2014-12-20T21:17:50.409000Z" ## ..$ url : chr "http://swapi.co/api/people/46/" ## $ :List of 14 ## ..$ name : chr "Dud Bolt" ## ..$ height : chr "94" ## ..$ mass : chr "45" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "blue, grey" ## ..$ eye_color : chr "yellow" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/39/" ## ..$ films : chr "http://swapi.co/api/films/4/" ## ..$ species : chr "http://swapi.co/api/species/17/" ## ..$ created : chr "2014-12-20T09:57:31.858000Z" ## ..$ edited : chr "2014-12-20T21:17:50.414000Z" ## ..$ url : chr "http://swapi.co/api/people/48/" ## $ :List of 14 ## ..$ name : chr "Gasgano" ## ..$ height : chr "122" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "white, blue" ## ..$ eye_color : chr "black" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/40/" ## ..$ films : chr "http://swapi.co/api/films/4/" ## ..$ species : chr "http://swapi.co/api/species/18/" ## ..$ created : chr "2014-12-20T10:02:12.223000Z" ## ..$ edited : chr "2014-12-20T21:17:50.416000Z" ## ..$ url : chr "http://swapi.co/api/people/49/" ## $ :List of 14 ## ..$ name : chr "Ben Quadinaros" ## ..$ height : chr "163" ## ..$ mass : chr "65" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "grey, green, yellow" ## ..$ eye_color : chr "orange" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/41/" ## ..$ films : chr "http://swapi.co/api/films/4/" ## ..$ species : chr "http://swapi.co/api/species/19/" ## ..$ created : chr "2014-12-20T10:08:33.777000Z" ## ..$ edited : chr "2014-12-20T21:17:50.417000Z" ## ..$ url : chr "http://swapi.co/api/people/50/" ## $ :List of 14 ## ..$ name : chr "Mace Windu" ## ..$ height : chr "188" ## ..$ mass : chr "84" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "dark" ## ..$ eye_color : chr "brown" ## ..$ birth_year: chr "72BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/42/" ## ..$ films : chr [1:3] "http://swapi.co/api/films/5/" "http://swapi.co/api/films/4/" "http://swapi.co/api/films/6/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ created : chr "2014-12-20T10:12:30.846000Z" ## ..$ edited : chr "2014-12-20T21:17:50.420000Z" ## ..$ url : chr "http://swapi.co/api/people/51/" ## $ :List of 14 ## ..$ name : chr "Ki-Adi-Mundi" ## ..$ height : chr "198" ## ..$ mass : chr "82" ## ..$ hair_color: chr "white" ## ..$ skin_color: chr "pale" ## ..$ eye_color : chr "yellow" ## ..$ birth_year: chr "92BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/43/" ## ..$ films : chr [1:3] "http://swapi.co/api/films/5/" "http://swapi.co/api/films/4/" "http://swapi.co/api/films/6/" ## ..$ species : chr "http://swapi.co/api/species/20/" ## ..$ created : chr "2014-12-20T10:15:32.293000Z" ## ..$ edited : chr "2014-12-20T21:17:50.422000Z" ## ..$ url : chr "http://swapi.co/api/people/52/" ## $ :List of 14 ## ..$ name : chr "Kit Fisto" ## ..$ height : chr "196" ## ..$ mass : chr "87" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "green" ## ..$ eye_color : chr "black" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/44/" ## ..$ films : chr [1:3] "http://swapi.co/api/films/5/" "http://swapi.co/api/films/4/" "http://swapi.co/api/films/6/" ## ..$ species : chr "http://swapi.co/api/species/21/" ## ..$ created : chr "2014-12-20T10:18:57.202000Z" ## ..$ edited : chr "2014-12-20T21:17:50.424000Z" ## ..$ url : chr "http://swapi.co/api/people/53/" ## $ :List of 14 ## ..$ name : chr "Eeth Koth" ## ..$ height : chr "171" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "black" ## ..$ skin_color: chr "brown" ## ..$ eye_color : chr "brown" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/45/" ## ..$ films : chr [1:2] "http://swapi.co/api/films/4/" "http://swapi.co/api/films/6/" ## ..$ species : chr "http://swapi.co/api/species/22/" ## ..$ created : chr "2014-12-20T10:26:47.902000Z" ## ..$ edited : chr "2014-12-20T21:17:50.427000Z" ## ..$ url : chr "http://swapi.co/api/people/54/" ## $ :List of 14 ## ..$ name : chr "Adi Gallia" ## ..$ height : chr "184" ## ..$ mass : chr "50" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "dark" ## ..$ eye_color : chr "blue" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "female" ## ..$ homeworld : chr "http://swapi.co/api/planets/9/" ## ..$ films : chr [1:2] "http://swapi.co/api/films/4/" "http://swapi.co/api/films/6/" ## ..$ species : chr "http://swapi.co/api/species/23/" ## ..$ created : chr "2014-12-20T10:29:11.661000Z" ## ..$ edited : chr "2014-12-20T21:17:50.432000Z" ## ..$ url : chr "http://swapi.co/api/people/55/" ## $ :List of 14 ## ..$ name : chr "Saesee Tiin" ## ..$ height : chr "188" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "pale" ## ..$ eye_color : chr "orange" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/47/" ## ..$ films : chr [1:2] "http://swapi.co/api/films/4/" "http://swapi.co/api/films/6/" ## ..$ species : chr "http://swapi.co/api/species/24/" ## ..$ created : chr "2014-12-20T10:32:11.669000Z" ## ..$ edited : chr "2014-12-20T21:17:50.434000Z" ## ..$ url : chr "http://swapi.co/api/people/56/" ## $ :List of 14 ## ..$ name : chr "Yarael Poof" ## ..$ height : chr "264" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "white" ## ..$ eye_color : chr "yellow" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/48/" ## ..$ films : chr "http://swapi.co/api/films/4/" ## ..$ species : chr "http://swapi.co/api/species/25/" ## ..$ created : chr "2014-12-20T10:34:48.725000Z" ## ..$ edited : chr "2014-12-20T21:17:50.437000Z" ## ..$ url : chr "http://swapi.co/api/people/57/" ## $ :List of 15 ## ..$ name : chr "Plo Koon" ## ..$ height : chr "188" ## ..$ mass : chr "80" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "orange" ## ..$ eye_color : chr "black" ## ..$ birth_year: chr "22BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/49/" ## ..$ films : chr [1:3] "http://swapi.co/api/films/5/" "http://swapi.co/api/films/4/" "http://swapi.co/api/films/6/" ## ..$ species : chr "http://swapi.co/api/species/26/" ## ..$ starships : chr "http://swapi.co/api/starships/48/" ## ..$ created : chr "2014-12-20T10:49:19.859000Z" ## ..$ edited : chr "2014-12-20T21:17:50.439000Z" ## ..$ url : chr "http://swapi.co/api/people/58/" ## $ :List of 14 ## ..$ name : chr "Mas Amedda" ## ..$ height : chr "196" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "blue" ## ..$ eye_color : chr "blue" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/50/" ## ..$ films : chr [1:2] "http://swapi.co/api/films/5/" "http://swapi.co/api/films/4/" ## ..$ species : chr "http://swapi.co/api/species/27/" ## ..$ created : chr "2014-12-20T10:53:26.457000Z" ## ..$ edited : chr "2014-12-20T21:17:50.442000Z" ## ..$ url : chr "http://swapi.co/api/people/59/" ## $ :List of 15 ## ..$ name : chr "Gregar Typho" ## ..$ height : chr "185" ## ..$ mass : chr "85" ## ..$ hair_color: chr "black" ## ..$ skin_color: chr "dark" ## ..$ eye_color : chr "brown" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/8/" ## ..$ films : chr "http://swapi.co/api/films/5/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ starships : chr "http://swapi.co/api/starships/39/" ## ..$ created : chr "2014-12-20T11:10:10.381000Z" ## ..$ edited : chr "2014-12-20T21:17:50.445000Z" ## ..$ url : chr "http://swapi.co/api/people/60/" ## $ :List of 14 ## ..$ name : chr "Cordé" ## ..$ height : chr "157" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "brown" ## ..$ skin_color: chr "light" ## ..$ eye_color : chr "brown" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "female" ## ..$ homeworld : chr "http://swapi.co/api/planets/8/" ## ..$ films : chr "http://swapi.co/api/films/5/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ created : chr "2014-12-20T11:11:39.630000Z" ## ..$ edited : chr "2014-12-20T21:17:50.449000Z" ## ..$ url : chr "http://swapi.co/api/people/61/" ## $ :List of 14 ## ..$ name : chr "Cliegg Lars" ## ..$ height : chr "183" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "brown" ## ..$ skin_color: chr "fair" ## ..$ eye_color : chr "blue" ## ..$ birth_year: chr "82BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/1/" ## ..$ films : chr "http://swapi.co/api/films/5/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ created : chr "2014-12-20T15:59:03.958000Z" ## ..$ edited : chr "2014-12-20T21:17:50.451000Z" ## ..$ url : chr "http://swapi.co/api/people/62/" ## $ :List of 14 ## ..$ name : chr "Poggle the Lesser" ## ..$ height : chr "183" ## ..$ mass : chr "80" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "green" ## ..$ eye_color : chr "yellow" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/11/" ## ..$ films : chr [1:2] "http://swapi.co/api/films/5/" "http://swapi.co/api/films/6/" ## ..$ species : chr "http://swapi.co/api/species/28/" ## ..$ created : chr "2014-12-20T16:40:43.977000Z" ## ..$ edited : chr "2014-12-20T21:17:50.453000Z" ## ..$ url : chr "http://swapi.co/api/people/63/" ## $ :List of 14 ## ..$ name : chr "Luminara Unduli" ## ..$ height : chr "170" ## ..$ mass : chr "56.2" ## ..$ hair_color: chr "black" ## ..$ skin_color: chr "yellow" ## ..$ eye_color : chr "blue" ## ..$ birth_year: chr "58BBY" ## ..$ gender : chr "female" ## ..$ homeworld : chr "http://swapi.co/api/planets/51/" ## ..$ films : chr [1:2] "http://swapi.co/api/films/5/" "http://swapi.co/api/films/6/" ## ..$ species : chr "http://swapi.co/api/species/29/" ## ..$ created : chr "2014-12-20T16:45:53.668000Z" ## ..$ edited : chr "2014-12-20T21:17:50.455000Z" ## ..$ url : chr "http://swapi.co/api/people/64/" ## $ :List of 14 ## ..$ name : chr "Barriss Offee" ## ..$ height : chr "166" ## ..$ mass : chr "50" ## ..$ hair_color: chr "black" ## ..$ skin_color: chr "yellow" ## ..$ eye_color : chr "blue" ## ..$ birth_year: chr "40BBY" ## ..$ gender : chr "female" ## ..$ homeworld : chr "http://swapi.co/api/planets/51/" ## ..$ films : chr "http://swapi.co/api/films/5/" ## ..$ species : chr "http://swapi.co/api/species/29/" ## ..$ created : chr "2014-12-20T16:46:40.440000Z" ## ..$ edited : chr "2014-12-20T21:17:50.457000Z" ## ..$ url : chr "http://swapi.co/api/people/65/" ## $ :List of 14 ## ..$ name : chr "Dormé" ## ..$ height : chr "165" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "brown" ## ..$ skin_color: chr "light" ## ..$ eye_color : chr "brown" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "female" ## ..$ homeworld : chr "http://swapi.co/api/planets/8/" ## ..$ films : chr "http://swapi.co/api/films/5/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ created : chr "2014-12-20T16:49:14.640000Z" ## ..$ edited : chr "2014-12-20T21:17:50.460000Z" ## ..$ url : chr "http://swapi.co/api/people/66/" ## $ :List of 15 ## ..$ name : chr "Dooku" ## ..$ height : chr "193" ## ..$ mass : chr "80" ## ..$ hair_color: chr "white" ## ..$ skin_color: chr "fair" ## ..$ eye_color : chr "brown" ## ..$ birth_year: chr "102BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/52/" ## ..$ films : chr [1:2] "http://swapi.co/api/films/5/" "http://swapi.co/api/films/6/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ vehicles : chr "http://swapi.co/api/vehicles/55/" ## ..$ created : chr "2014-12-20T16:52:14.726000Z" ## ..$ edited : chr "2014-12-20T21:17:50.462000Z" ## ..$ url : chr "http://swapi.co/api/people/67/" ## $ :List of 14 ## ..$ name : chr "Bail Prestor Organa" ## ..$ height : chr "191" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "black" ## ..$ skin_color: chr "tan" ## ..$ eye_color : chr "brown" ## ..$ birth_year: chr "67BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/2/" ## ..$ films : chr [1:2] "http://swapi.co/api/films/5/" "http://swapi.co/api/films/6/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ created : chr "2014-12-20T16:53:08.575000Z" ## ..$ edited : chr "2014-12-20T21:17:50.463000Z" ## ..$ url : chr "http://swapi.co/api/people/68/" ## $ :List of 14 ## ..$ name : chr "Jango Fett" ## ..$ height : chr "183" ## ..$ mass : chr "79" ## ..$ hair_color: chr "black" ## ..$ skin_color: chr "tan" ## ..$ eye_color : chr "brown" ## ..$ birth_year: chr "66BBY" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/53/" ## ..$ films : chr "http://swapi.co/api/films/5/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ created : chr "2014-12-20T16:54:41.620000Z" ## ..$ edited : chr "2014-12-20T21:17:50.465000Z" ## ..$ url : chr "http://swapi.co/api/people/69/" ## $ :List of 15 ## ..$ name : chr "Zam Wesell" ## ..$ height : chr "168" ## ..$ mass : chr "55" ## ..$ hair_color: chr "blonde" ## ..$ skin_color: chr "fair, green, yellow" ## ..$ eye_color : chr "yellow" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "female" ## ..$ homeworld : chr "http://swapi.co/api/planets/54/" ## ..$ films : chr "http://swapi.co/api/films/5/" ## ..$ species : chr "http://swapi.co/api/species/30/" ## ..$ vehicles : chr "http://swapi.co/api/vehicles/45/" ## ..$ created : chr "2014-12-20T16:57:44.471000Z" ## ..$ edited : chr "2014-12-20T21:17:50.468000Z" ## ..$ url : chr "http://swapi.co/api/people/70/" ## $ :List of 14 ## ..$ name : chr "Dexter Jettster" ## ..$ height : chr "198" ## ..$ mass : chr "102" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "brown" ## ..$ eye_color : chr "yellow" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/55/" ## ..$ films : chr "http://swapi.co/api/films/5/" ## ..$ species : chr "http://swapi.co/api/species/31/" ## ..$ created : chr "2014-12-20T17:28:27.248000Z" ## ..$ edited : chr "2014-12-20T21:17:50.470000Z" ## ..$ url : chr "http://swapi.co/api/people/71/" ## $ :List of 14 ## ..$ name : chr "Lama Su" ## ..$ height : chr "229" ## ..$ mass : chr "88" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "grey" ## ..$ eye_color : chr "black" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/10/" ## ..$ films : chr "http://swapi.co/api/films/5/" ## ..$ species : chr "http://swapi.co/api/species/32/" ## ..$ created : chr "2014-12-20T17:30:50.416000Z" ## ..$ edited : chr "2014-12-20T21:17:50.473000Z" ## ..$ url : chr "http://swapi.co/api/people/72/" ## $ :List of 14 ## ..$ name : chr "Taun We" ## ..$ height : chr "213" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "grey" ## ..$ eye_color : chr "black" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "female" ## ..$ homeworld : chr "http://swapi.co/api/planets/10/" ## ..$ films : chr "http://swapi.co/api/films/5/" ## ..$ species : chr "http://swapi.co/api/species/32/" ## ..$ created : chr "2014-12-20T17:31:21.195000Z" ## ..$ edited : chr "2014-12-20T21:17:50.474000Z" ## ..$ url : chr "http://swapi.co/api/people/73/" ## $ :List of 14 ## ..$ name : chr "Jocasta Nu" ## ..$ height : chr "167" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "white" ## ..$ skin_color: chr "fair" ## ..$ eye_color : chr "blue" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "female" ## ..$ homeworld : chr "http://swapi.co/api/planets/9/" ## ..$ films : chr "http://swapi.co/api/films/5/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ created : chr "2014-12-20T17:32:51.996000Z" ## ..$ edited : chr "2014-12-20T21:17:50.476000Z" ## ..$ url : chr "http://swapi.co/api/people/74/" ## $ :List of 14 ## ..$ name : chr "Ratts Tyerell" ## ..$ height : chr "79" ## ..$ mass : chr "15" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "grey, blue" ## ..$ eye_color : chr "unknown" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/38/" ## ..$ films : chr "http://swapi.co/api/films/4/" ## ..$ species : chr "http://swapi.co/api/species/16/" ## ..$ created : chr "2014-12-20T09:53:15.086000Z" ## ..$ edited : chr "2016-06-30T12:52:19.604868Z" ## ..$ url : chr "http://swapi.co/api/people/47/" ## $ :List of 13 ## ..$ name : chr "R4-P17" ## ..$ height : chr "96" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "silver, red" ## ..$ eye_color : chr "red, blue" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "female" ## ..$ homeworld : chr "http://swapi.co/api/planets/28/" ## ..$ films : chr [1:2] "http://swapi.co/api/films/5/" "http://swapi.co/api/films/6/" ## ..$ created : chr "2014-12-20T17:43:36.409000Z" ## ..$ edited : chr "2014-12-20T21:17:50.478000Z" ## ..$ url : chr "http://swapi.co/api/people/75/" ## $ :List of 14 ## ..$ name : chr "Wat Tambor" ## ..$ height : chr "193" ## ..$ mass : chr "48" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "green, grey" ## ..$ eye_color : chr "unknown" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/56/" ## ..$ films : chr "http://swapi.co/api/films/5/" ## ..$ species : chr "http://swapi.co/api/species/33/" ## ..$ created : chr "2014-12-20T17:53:52.607000Z" ## ..$ edited : chr "2014-12-20T21:17:50.481000Z" ## ..$ url : chr "http://swapi.co/api/people/76/" ## $ :List of 14 ## ..$ name : chr "San Hill" ## ..$ height : chr "191" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "grey" ## ..$ eye_color : chr "gold" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/57/" ## ..$ films : chr "http://swapi.co/api/films/5/" ## ..$ species : chr "http://swapi.co/api/species/34/" ## ..$ created : chr "2014-12-20T17:58:17.049000Z" ## ..$ edited : chr "2014-12-20T21:17:50.484000Z" ## ..$ url : chr "http://swapi.co/api/people/77/" ## $ :List of 14 ## ..$ name : chr "Shaak Ti" ## ..$ height : chr "178" ## ..$ mass : chr "57" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "red, blue, white" ## ..$ eye_color : chr "black" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "female" ## ..$ homeworld : chr "http://swapi.co/api/planets/58/" ## ..$ films : chr [1:2] "http://swapi.co/api/films/5/" "http://swapi.co/api/films/6/" ## ..$ species : chr "http://swapi.co/api/species/35/" ## ..$ created : chr "2014-12-20T18:44:01.103000Z" ## ..$ edited : chr "2014-12-20T21:17:50.486000Z" ## ..$ url : chr "http://swapi.co/api/people/78/" ## $ :List of 16 ## ..$ name : chr "Grievous" ## ..$ height : chr "216" ## ..$ mass : chr "159" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "brown, white" ## ..$ eye_color : chr "green, yellow" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/59/" ## ..$ films : chr "http://swapi.co/api/films/6/" ## ..$ species : chr "http://swapi.co/api/species/36/" ## ..$ vehicles : chr "http://swapi.co/api/vehicles/60/" ## ..$ starships : chr "http://swapi.co/api/starships/74/" ## ..$ created : chr "2014-12-20T19:43:53.348000Z" ## ..$ edited : chr "2014-12-20T21:17:50.488000Z" ## ..$ url : chr "http://swapi.co/api/people/79/" ## $ :List of 14 ## ..$ name : chr "Tarfful" ## ..$ height : chr "234" ## ..$ mass : chr "136" ## ..$ hair_color: chr "brown" ## ..$ skin_color: chr "brown" ## ..$ eye_color : chr "blue" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/14/" ## ..$ films : chr "http://swapi.co/api/films/6/" ## ..$ species : chr "http://swapi.co/api/species/3/" ## ..$ created : chr "2014-12-20T19:46:34.209000Z" ## ..$ edited : chr "2014-12-20T21:17:50.491000Z" ## ..$ url : chr "http://swapi.co/api/people/80/" ## $ :List of 14 ## ..$ name : chr "Raymus Antilles" ## ..$ height : chr "188" ## ..$ mass : chr "79" ## ..$ hair_color: chr "brown" ## ..$ skin_color: chr "light" ## ..$ eye_color : chr "brown" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/2/" ## ..$ films : chr [1:2] "http://swapi.co/api/films/6/" "http://swapi.co/api/films/1/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ created : chr "2014-12-20T19:49:35.583000Z" ## ..$ edited : chr "2014-12-20T21:17:50.493000Z" ## ..$ url : chr "http://swapi.co/api/people/81/" ## $ :List of 13 ## ..$ name : chr "Sly Moore" ## ..$ height : chr "178" ## ..$ mass : chr "48" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "pale" ## ..$ eye_color : chr "white" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "female" ## ..$ homeworld : chr "http://swapi.co/api/planets/60/" ## ..$ films : chr [1:2] "http://swapi.co/api/films/5/" "http://swapi.co/api/films/6/" ## ..$ created : chr "2014-12-20T20:18:37.619000Z" ## ..$ edited : chr "2014-12-20T21:17:50.496000Z" ## ..$ url : chr "http://swapi.co/api/people/82/" ## $ :List of 14 ## ..$ name : chr "Tion Medon" ## ..$ height : chr "206" ## ..$ mass : chr "80" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "grey" ## ..$ eye_color : chr "black" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/12/" ## ..$ films : chr "http://swapi.co/api/films/6/" ## ..$ species : chr "http://swapi.co/api/species/37/" ## ..$ created : chr "2014-12-20T20:35:04.260000Z" ## ..$ edited : chr "2014-12-20T21:17:50.498000Z" ## ..$ url : chr "http://swapi.co/api/people/83/" ## $ :List of 14 ## ..$ name : chr "Finn" ## ..$ height : chr "unknown" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "black" ## ..$ skin_color: chr "dark" ## ..$ eye_color : chr "dark" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/28/" ## ..$ films : chr "http://swapi.co/api/films/7/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ created : chr "2015-04-17T06:52:40.793621Z" ## ..$ edited : chr "2015-04-17T06:52:40.793674Z" ## ..$ url : chr "http://swapi.co/api/people/84/" ## $ :List of 14 ## ..$ name : chr "Rey" ## ..$ height : chr "unknown" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "brown" ## ..$ skin_color: chr "light" ## ..$ eye_color : chr "hazel" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "female" ## ..$ homeworld : chr "http://swapi.co/api/planets/28/" ## ..$ films : chr "http://swapi.co/api/films/7/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ created : chr "2015-04-17T06:54:01.495077Z" ## ..$ edited : chr "2015-04-17T06:54:01.495128Z" ## ..$ url : chr "http://swapi.co/api/people/85/" ## $ :List of 15 ## ..$ name : chr "Poe Dameron" ## ..$ height : chr "unknown" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "brown" ## ..$ skin_color: chr "light" ## ..$ eye_color : chr "brown" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "male" ## ..$ homeworld : chr "http://swapi.co/api/planets/28/" ## ..$ films : chr "http://swapi.co/api/films/7/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ starships : chr "http://swapi.co/api/starships/77/" ## ..$ created : chr "2015-04-17T06:55:21.622786Z" ## ..$ edited : chr "2015-04-17T06:55:21.622835Z" ## ..$ url : chr "http://swapi.co/api/people/86/" ## $ :List of 14 ## ..$ name : chr "BB8" ## ..$ height : chr "unknown" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "none" ## ..$ skin_color: chr "none" ## ..$ eye_color : chr "black" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "none" ## ..$ homeworld : chr "http://swapi.co/api/planets/28/" ## ..$ films : chr "http://swapi.co/api/films/7/" ## ..$ species : chr "http://swapi.co/api/species/2/" ## ..$ created : chr "2015-04-17T06:57:38.061346Z" ## ..$ edited : chr "2015-04-17T06:57:38.061453Z" ## ..$ url : chr "http://swapi.co/api/people/87/" ## $ :List of 13 ## ..$ name : chr "Captain Phasma" ## ..$ height : chr "unknown" ## ..$ mass : chr "unknown" ## ..$ hair_color: chr "unknown" ## ..$ skin_color: chr "unknown" ## ..$ eye_color : chr "unknown" ## ..$ birth_year: chr "unknown" ## ..$ gender : chr "female" ## ..$ homeworld : chr "http://swapi.co/api/planets/28/" ## ..$ films : chr "http://swapi.co/api/films/7/" ## ..$ created : chr "2015-10-13T10:35:39.229823Z" ## ..$ edited : chr "2015-10-13T10:35:39.229894Z" ## ..$ url : chr "http://swapi.co/api/people/88/" ## $ :List of 15 ## ..$ name : chr "Padmé Amidala" ## ..$ height : chr "165" ## ..$ mass : chr "45" ## ..$ hair_color: chr "brown" ## ..$ skin_color: chr "light" ## ..$ eye_color : chr "brown" ## ..$ birth_year: chr "46BBY" ## ..$ gender : chr "female" ## ..$ homeworld : chr "http://swapi.co/api/planets/8/" ## ..$ films : chr [1:3] "http://swapi.co/api/films/5/" "http://swapi.co/api/films/4/" "http://swapi.co/api/films/6/" ## ..$ species : chr "http://swapi.co/api/species/1/" ## ..$ starships : chr [1:3] "http://swapi.co/api/starships/49/" "http://swapi.co/api/starships/64/" "http://swapi.co/api/starships/39/" ## ..$ created : chr "2014-12-19T17:28:26.926000Z" ## ..$ edited : chr "2016-04-20T17:06:31.502555Z" ## ..$ url : chr "http://swapi.co/api/people/35/"
length(sw_people)
## [1] 87
Run this in your console:
View(sw_people)
Then let's answer:
sw_people[[1]] # Luke!
## $name ## [1] "Luke Skywalker" ## ## $height ## [1] "172" ## ## $mass ## [1] "77" ## ## $hair_color ## [1] "blond" ## ## $skin_color ## [1] "fair" ## ## $eye_color ## [1] "blue" ## ## $birth_year ## [1] "19BBY" ## ## $gender ## [1] "male" ## ## $homeworld ## [1] "http://swapi.co/api/planets/1/" ## ## $films ## [1] "http://swapi.co/api/films/6/" "http://swapi.co/api/films/3/" ## [3] "http://swapi.co/api/films/2/" "http://swapi.co/api/films/1/" ## [5] "http://swapi.co/api/films/7/" ## ## $species ## [1] "http://swapi.co/api/species/1/" ## ## $vehicles ## [1] "http://swapi.co/api/vehicles/14/" "http://swapi.co/api/vehicles/30/" ## ## $starships ## [1] "http://swapi.co/api/starships/12/" "http://swapi.co/api/starships/22/" ## ## $created ## [1] "2014-12-09T13:50:51.644000Z" ## ## $edited ## [1] "2014-12-20T21:17:56.891000Z" ## ## $url ## [1] "http://swapi.co/api/people/1/"
sw_people[1]
## [[1]] ## [[1]]$name ## [1] "Luke Skywalker" ## ## [[1]]$height ## [1] "172" ## ## [[1]]$mass ## [1] "77" ## ## [[1]]$hair_color ## [1] "blond" ## ## [[1]]$skin_color ## [1] "fair" ## ## [[1]]$eye_color ## [1] "blue" ## ## [[1]]$birth_year ## [1] "19BBY" ## ## [[1]]$gender ## [1] "male" ## ## [[1]]$homeworld ## [1] "http://swapi.co/api/planets/1/" ## ## [[1]]$films ## [1] "http://swapi.co/api/films/6/" "http://swapi.co/api/films/3/" ## [3] "http://swapi.co/api/films/2/" "http://swapi.co/api/films/1/" ## [5] "http://swapi.co/api/films/7/" ## ## [[1]]$species ## [1] "http://swapi.co/api/species/1/" ## ## [[1]]$vehicles ## [1] "http://swapi.co/api/vehicles/14/" "http://swapi.co/api/vehicles/30/" ## ## [[1]]$starships ## [1] "http://swapi.co/api/starships/12/" "http://swapi.co/api/starships/22/" ## ## [[1]]$created ## [1] "2014-12-09T13:50:51.644000Z" ## ## [[1]]$edited ## [1] "2014-12-20T21:17:56.891000Z" ## ## [[1]]$url ## [1] "http://swapi.co/api/people/1/"
sw_people[[1]]
## $name ## [1] "Luke Skywalker" ## ## $height ## [1] "172" ## ## $mass ## [1] "77" ## ## $hair_color ## [1] "blond" ## ## $skin_color ## [1] "fair" ## ## $eye_color ## [1] "blue" ## ## $birth_year ## [1] "19BBY" ## ## $gender ## [1] "male" ## ## $homeworld ## [1] "http://swapi.co/api/planets/1/" ## ## $films ## [1] "http://swapi.co/api/films/6/" "http://swapi.co/api/films/3/" ## [3] "http://swapi.co/api/films/2/" "http://swapi.co/api/films/1/" ## [5] "http://swapi.co/api/films/7/" ## ## $species ## [1] "http://swapi.co/api/species/1/" ## ## $vehicles ## [1] "http://swapi.co/api/vehicles/14/" "http://swapi.co/api/vehicles/30/" ## ## $starships ## [1] "http://swapi.co/api/starships/12/" "http://swapi.co/api/starships/22/" ## ## $created ## [1] "2014-12-09T13:50:51.644000Z" ## ## $edited ## [1] "2014-12-20T21:17:56.891000Z" ## ## $url ## [1] "http://swapi.co/api/people/1/"
mapmap( .x, .f, ...)
For each element of .x do .f:
.x can be a vector, a list, or a data frame
map(sw_people, _____)
Strategy:
map() to do it for all elementsSave Luke:
luke <- sw_people[[1]]
length(luke$starships)
## [1] 2
leia <- sw_people[[?]]
length(leia$starships)
___ <- sw_people[[___]]
length(___$starships)
~ length( .x $ starships)
~: A formula.x: purrr's "pronoun" for one element of our vectormap()map(sw_people, ~ length(.x$starships))
## [[1]] ## [1] 2 ## ## [[2]] ## [1] 0 ## ## [[3]] ## [1] 0 ## ## [[4]] ## [1] 1 ## ## [[5]] ## [1] 0 ## ## [[6]] ## [1] 0 ## ## [[7]] ## [1] 0 ## ## [[8]] ## [1] 0 ## ## [[9]] ## [1] 1 ## ## [[10]] ## [1] 5 ## ## [[11]] ## [1] 3 ## ## [[12]] ## [1] 0 ## ## [[13]] ## [1] 2 ## ## [[14]] ## [1] 2 ## ## [[15]] ## [1] 0 ## ## [[16]] ## [1] 0 ## ## [[17]] ## [1] 1 ## ## [[18]] ## [1] 1 ## ## [[19]] ## [1] 0 ## ## [[20]] ## [1] 0 ## ## [[21]] ## [1] 1 ## ## [[22]] ## [1] 0 ## ## [[23]] ## [1] 0 ## ## [[24]] ## [1] 1 ## ## [[25]] ## [1] 0 ## ## [[26]] ## [1] 0 ## ## [[27]] ## [1] 0 ## ## [[28]] ## [1] 1 ## ## [[29]] ## [1] 0 ## ## [[30]] ## [1] 1 ## ## [[31]] ## [1] 0 ## ## [[32]] ## [1] 0 ## ## [[33]] ## [1] 0 ## ## [[34]] ## [1] 0 ## ## [[35]] ## [1] 0 ## ## [[36]] ## [1] 0 ## ## [[37]] ## [1] 1 ## ## [[38]] ## [1] 0 ## ## [[39]] ## [1] 0 ## ## [[40]] ## [1] 0 ## ## [[41]] ## [1] 0 ## ## [[42]] ## [1] 1 ## ## [[43]] ## [1] 0 ## ## [[44]] ## [1] 0 ## ## [[45]] ## [1] 0 ## ## [[46]] ## [1] 0 ## ## [[47]] ## [1] 0 ## ## [[48]] ## [1] 0 ## ## [[49]] ## [1] 0 ## ## [[50]] ## [1] 0 ## ## [[51]] ## [1] 0 ## ## [[52]] ## [1] 0 ## ## [[53]] ## [1] 0 ## ## [[54]] ## [1] 0 ## ## [[55]] ## [1] 1 ## ## [[56]] ## [1] 0 ## ## [[57]] ## [1] 1 ## ## [[58]] ## [1] 0 ## ## [[59]] ## [1] 0 ## ## [[60]] ## [1] 0 ## ## [[61]] ## [1] 0 ## ## [[62]] ## [1] 0 ## ## [[63]] ## [1] 0 ## ## [[64]] ## [1] 0 ## ## [[65]] ## [1] 0 ## ## [[66]] ## [1] 0 ## ## [[67]] ## [1] 0 ## ## [[68]] ## [1] 0 ## ## [[69]] ## [1] 0 ## ## [[70]] ## [1] 0 ## ## [[71]] ## [1] 0 ## ## [[72]] ## [1] 0 ## ## [[73]] ## [1] 0 ## ## [[74]] ## [1] 0 ## ## [[75]] ## [1] 0 ## ## [[76]] ## [1] 0 ## ## [[77]] ## [1] 1 ## ## [[78]] ## [1] 0 ## ## [[79]] ## [1] 0 ## ## [[80]] ## [1] 0 ## ## [[81]] ## [1] 0 ## ## [[82]] ## [1] 0 ## ## [[83]] ## [1] 0 ## ## [[84]] ## [1] 1 ## ## [[85]] ## [1] 0 ## ## [[86]] ## [1] 0 ## ## [[87]] ## [1] 3
map() & friendsmap_something.fmap2 - variants of map() that iterate over multiple arguments in parallel (but I might not get to this today)Basic functions for looping over an object and returning a value (of a specific type) - replacement for lapply/sapply/vapply.
map() - returns a list.
map_lgl() - returns a logical vector.
map_int() - returns a integer vector.
map_dbl() - returns a double vector.
map_chr() - returns a character vector.
map_df() / map_dfr() - returns a data frame by row binding.
map_dfc() - returns a data frame by column binding.
walk() - returns nothing, call function exclusively for its side effects
map_???(sw_people, ~ length(.x[["starships"]]))
map_int(sw_people, ~ length(.x[["starships"]]))
## [1] 2 0 0 1 0 0 0 0 1 5 3 0 2 2 0 0 1 1 0 0 1 0 0 1 0 0 0 1 0 1 0 0 0 0 0 ## [36] 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 ## [71] 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 3
map_???(sw_people, ~ .x[["hair_color"]])
map_chr(sw_people, ~ .x[["hair_color"]])
## [1] "blond" "n/a" "n/a" "none" ## [5] "brown" "brown, grey" "brown" "n/a" ## [9] "black" "auburn, white" "blond" "auburn, grey" ## [13] "brown" "brown" "n/a" "n/a" ## [17] "brown" "brown" "white" "grey" ## [21] "black" "none" "none" "black" ## [25] "none" "none" "auburn" "brown" ## [29] "brown" "none" "brown" "none" ## [33] "blond" "none" "none" "none" ## [37] "brown" "black" "none" "black" ## [41] "black" "none" "none" "none" ## [45] "none" "none" "none" "none" ## [49] "white" "none" "black" "none" ## [53] "none" "none" "none" "none" ## [57] "black" "brown" "brown" "none" ## [61] "black" "black" "brown" "white" ## [65] "black" "black" "blonde" "none" ## [69] "none" "none" "white" "none" ## [73] "none" "none" "none" "none" ## [77] "none" "brown" "brown" "none" ## [81] "none" "black" "brown" "brown" ## [85] "none" "unknown" "brown"
map_???(sw_people, ~ .x[["gender"]] == "male")
map_lgl(sw_people, ~ .x[["gender"]] == "male")
## [1] TRUE FALSE FALSE TRUE FALSE TRUE FALSE FALSE TRUE TRUE TRUE ## [12] TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE FALSE ## [23] TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE ## [34] TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE FALSE ## [45] TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE ## [56] TRUE TRUE FALSE TRUE TRUE FALSE FALSE FALSE TRUE TRUE TRUE ## [67] FALSE TRUE TRUE FALSE FALSE TRUE FALSE TRUE TRUE FALSE TRUE ## [78] TRUE TRUE FALSE TRUE TRUE FALSE TRUE FALSE FALSE FALSE
Why don't these work / what is not ideal about them? How would you fix it?
map_dbl(sw_people, ~ .x[["mass"]]) map(sw_people, ~ .x[["mass"]]) map_dbl(sw_people, ~ as.numeric(.x[["mass"]]))
map_chr(sw_people, ~ .x[["mass"]]) %>% readr::parse_number(na = "unknown")
## [1] 77.0 75.0 32.0 136.0 49.0 120.0 75.0 32.0 84.0 77.0 ## [11] 84.0 NA 112.0 80.0 74.0 1358.0 77.0 110.0 17.0 75.0 ## [21] 78.2 140.0 113.0 79.0 79.0 83.0 NA NA 20.0 68.0 ## [31] 89.0 90.0 NA 66.0 82.0 NA NA NA 40.0 NA ## [41] NA 80.0 NA 55.0 45.0 NA 65.0 84.0 82.0 87.0 ## [51] NA 50.0 NA NA 80.0 NA 85.0 NA NA 80.0 ## [61] 56.2 50.0 NA 80.0 NA 79.0 55.0 102.0 88.0 NA ## [71] NA 15.0 NA 48.0 NA 57.0 159.0 136.0 79.0 48.0 ## [81] 80.0 NA NA NA NA NA 45.0
map()map( .x, .f = ~ DO SOMETHING WITH .x)
.f can be
.f can be a formulaWhat do each of these do?
map_int(sw_people, ~ length(.x[["starships"]])) map_chr(sw_people, ~ .x[["hair_color"]]) map_chr(sw_people, ~ .x[["mass"]])
.f can be a string or integerHow do these compare?
map_chr(sw_people, ~ .x[["hair_color"]]) map_chr(sw_people, "hair_color")
.f can be a functionWhat do these do?
char_starships <- map(sw_people, "starships") map_int(char_starships, length)
map(sw_people, "starships") %>% map_int(length) map_int(sw_people, ~ length(.x[["starships"]]))
What's wrong with this?
map(sw_people, "startships") %>% map_int(length)
## [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ## [36] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ## [71] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
sapply() and apply()?Motivation for purrr:
consistent return type
useful shortcuts
consistent syntax for more complicated iteration