Skip to content

Instantly share code, notes, and snippets.

@PatrickRWright
Created August 5, 2020 07:59
Show Gist options
  • Save PatrickRWright/4d559f0f943f60d3594bdc93f99676db to your computer and use it in GitHub Desktop.
Save PatrickRWright/4d559f0f943f60d3594bdc93f99676db to your computer and use it in GitHub Desktop.
Created on Skills Network Labs
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Dictionaries in R"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There are cases where you may want to use a dictionary-type approach to label values. There are many possible solutions to this. Here we will look at a case where one value can be used to find an associated value in the dictionary. **We will use a named vector**. A simple example is a phone book. For simplicity we assume that people's names are unique."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's first create a vector of phone numbers:"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<style>\n",
".list-inline {list-style: none; margin:0; padding: 0}\n",
".list-inline>li {display: inline-block}\n",
".list-inline>li:not(:last-child)::after {content: \"\\00b7\"; padding: 0 .5ex}\n",
"</style>\n",
"<ol class=list-inline><li>'6615439332'</li><li>'9982919943'</li><li>'8712699959'</li><li>'9173869732'</li><li>'7856213414'</li><li>'9764732656'</li></ol>\n"
],
"text/latex": [
"\\begin{enumerate*}\n",
"\\item '6615439332'\n",
"\\item '9982919943'\n",
"\\item '8712699959'\n",
"\\item '9173869732'\n",
"\\item '7856213414'\n",
"\\item '9764732656'\n",
"\\end{enumerate*}\n"
],
"text/markdown": [
"1. '6615439332'\n",
"2. '9982919943'\n",
"3. '8712699959'\n",
"4. '9173869732'\n",
"5. '7856213414'\n",
"6. '9764732656'\n",
"\n",
"\n"
],
"text/plain": [
"[1] \"6615439332\" \"9982919943\" \"8712699959\" \"9173869732\" \"7856213414\"\n",
"[6] \"9764732656\""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# seed\n",
"set.seed(1337)\n",
"# 100 numbers\n",
"phone_nums <- replicate(100, paste0(sample(1:9, size = 10, replace = TRUE), collapse = \"\"))\n",
"head(phone_nums)"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"TRUE"
],
"text/latex": [
"TRUE"
],
"text/markdown": [
"TRUE"
],
"text/plain": [
"[1] TRUE"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<style>\n",
".list-inline {list-style: none; margin:0; padding: 0}\n",
".list-inline>li {display: inline-block}\n",
".list-inline>li:not(:last-child)::after {content: \"\\00b7\"; padding: 0 .5ex}\n",
"</style>\n",
"<ol class=list-inline><li>'Rosie Bowman'</li><li>'Connor Knight'</li><li>'Jackson Rice'</li><li>'Gerry Graham'</li><li>'Javier Griffin'</li><li>'Katherine Frazier'</li></ol>\n"
],
"text/latex": [
"\\begin{enumerate*}\n",
"\\item 'Rosie Bowman'\n",
"\\item 'Connor Knight'\n",
"\\item 'Jackson Rice'\n",
"\\item 'Gerry Graham'\n",
"\\item 'Javier Griffin'\n",
"\\item 'Katherine Frazier'\n",
"\\end{enumerate*}\n"
],
"text/markdown": [
"1. 'Rosie Bowman'\n",
"2. 'Connor Knight'\n",
"3. 'Jackson Rice'\n",
"4. 'Gerry Graham'\n",
"5. 'Javier Griffin'\n",
"6. 'Katherine Frazier'\n",
"\n",
"\n"
],
"text/plain": [
"[1] \"Rosie Bowman\" \"Connor Knight\" \"Jackson Rice\" \n",
"[4] \"Gerry Graham\" \"Javier Griffin\" \"Katherine Frazier\""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"library(randNames)\n",
"people <- rand_names(100, nationality = \"GB\", seed = 1337)\n",
"people_names <- paste(people$name.first, people$name.last)\n",
"# check if unique\n",
"length(unique(people_names)) == 100\n",
"head(people_names)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create a named vector."
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<style>\n",
".dl-inline {width: auto; margin:0; padding: 0}\n",
".dl-inline>dt, .dl-inline>dd {float: none; width: auto; display: inline-block}\n",
".dl-inline>dt::after {content: \":\\0020\"; padding-right: .5ex}\n",
".dl-inline>dt:not(:first-of-type) {padding-left: .5ex}\n",
"</style><dl class=dl-inline><dt>Rosie Bowman</dt><dd>'6615439332'</dd><dt>Connor Knight</dt><dd>'9982919943'</dd><dt>Jackson Rice</dt><dd>'8712699959'</dd><dt>Gerry Graham</dt><dd>'9173869732'</dd><dt>Javier Griffin</dt><dd>'7856213414'</dd><dt>Katherine Frazier</dt><dd>'9764732656'</dd><dt>Wayne Mitchelle</dt><dd>'9389229535'</dd><dt>Linda Lane</dt><dd>'4831742356'</dd><dt>Erik Vargas</dt><dd>'9712597539'</dd><dt>Izzie Curtis</dt><dd>'8675747339'</dd><dt>Angela Wade</dt><dd>'5588312235'</dd><dt>Frederick Davies</dt><dd>'8212726576'</dd><dt>Leah Daniels</dt><dd>'1866817987'</dd><dt>Julie Clark</dt><dd>'7593953313'</dd><dt>Angela Olson</dt><dd>'7545216358'</dd><dt>Lance Fields</dt><dd>'7233578444'</dd><dt>Gabe Hudson</dt><dd>'4995975496'</dd><dt>Carolyn Mckinney</dt><dd>'2226228237'</dd><dt>Albert Evans</dt><dd>'8915525682'</dd><dt>Tracy Payne</dt><dd>'8675565482'</dd><dt>Elmer Williamson</dt><dd>'6143916348'</dd><dt>Marshall Diaz</dt><dd>'2327795536'</dd><dt>Andrea Berry</dt><dd>'3932358866'</dd><dt>Diane Hayes</dt><dd>'6127614281'</dd><dt>Jose Murphy</dt><dd>'4954311953'</dd><dt>Herman Miller</dt><dd>'9737313414'</dd><dt>Jennifer Gordon</dt><dd>'3568394793'</dd><dt>Tracey Ramirez</dt><dd>'6297979277'</dd><dt>Levi Harris</dt><dd>'4224592664'</dd><dt>Salvador Fletcher</dt><dd>'6142845797'</dd><dt>Isabella Holmes</dt><dd>'1724765495'</dd><dt>Dylan Carroll</dt><dd>'4741174722'</dd><dt>Claude Rose</dt><dd>'4923217947'</dd><dt>Brayden Fields</dt><dd>'3853314997'</dd><dt>Katie Marshall</dt><dd>'8222825122'</dd><dt>Suzanne Jennings</dt><dd>'6576943995'</dd><dt>Rosalyn Byrd</dt><dd>'7253581738'</dd><dt>Arnold Rogers</dt><dd>'2591732879'</dd><dt>Lisa Pena</dt><dd>'4471189654'</dd><dt>Avery Pena</dt><dd>'9566552291'</dd><dt>Karen Grant</dt><dd>'8264212844'</dd><dt>Edwin Wright</dt><dd>'5227394171'</dd><dt>Ashley James</dt><dd>'2625261646'</dd><dt>Arthur Austin</dt><dd>'5414736426'</dd><dt>Catherine Castillo</dt><dd>'9914781622'</dd><dt>Mary Kennedy</dt><dd>'6972144772'</dd><dt>Sophie Smith</dt><dd>'8378648123'</dd><dt>Austin Alvarez</dt><dd>'7554529522'</dd><dt>Roland Jimenez</dt><dd>'1732971876'</dd><dt>Mary Hale</dt><dd>'8994466533'</dd><dt>Paige Elliott</dt><dd>'1985127877'</dd><dt>Gabriel Ryan</dt><dd>'5153716534'</dd><dt>Mario Harvey</dt><dd>'6266137478'</dd><dt>Debra Lord</dt><dd>'5759231777'</dd><dt>Kim Clarke</dt><dd>'1112561989'</dd><dt>Jason Hoffman</dt><dd>'4356531274'</dd><dt>Alfredo Sims</dt><dd>'3325868858'</dd><dt>Susie Coleman</dt><dd>'3526347392'</dd><dt>Brennan Holt</dt><dd>'7559353559'</dd><dt>Bob Nguyen</dt><dd>'4296137972'</dd><dt>Josef Hanson</dt><dd>'7638259959'</dd><dt>Jerry Macrae</dt><dd>'1294779948'</dd><dt>Heather Watts</dt><dd>'4343452674'</dd><dt>Isabella Little</dt><dd>'8291167476'</dd><dt>Deborah Johnson</dt><dd>'6848854433'</dd><dt>Laura Ray</dt><dd>'7214313942'</dd><dt>Chad Sullivan</dt><dd>'7616634797'</dd><dt>Gabe Burton</dt><dd>'3357823729'</dd><dt>Suzy Edwards</dt><dd>'3115996814'</dd><dt>Sofia Cook</dt><dd>'8728786727'</dd><dt>Lillian Perkins</dt><dd>'1373463215'</dd><dt>Zander Lord</dt><dd>'2242251789'</dd><dt>Gerry May</dt><dd>'7673671557'</dd><dt>Callum Roberts</dt><dd>'1792536149'</dd><dt>Randall Davidson</dt><dd>'2342638893'</dd><dt>Carol Franklin</dt><dd>'4898626852'</dd><dt>Eugene Hunter</dt><dd>'5535845644'</dd><dt>Abbie Herrera</dt><dd>'7825426887'</dd><dt>George Riley</dt><dd>'9233283553'</dd><dt>Scarlett Moreno</dt><dd>'1279256655'</dd><dt>Janet Welch</dt><dd>'5245312375'</dd><dt>Vicky Bradley</dt><dd>'2896595195'</dd><dt>Walter Hawkins</dt><dd>'8794351787'</dd><dt>Jose Collins</dt><dd>'9529823429'</dd><dt>Greg Simmons</dt><dd>'2633693539'</dd><dt>Amy Richardson</dt><dd>'6525111453'</dd><dt>Kelly Foster</dt><dd>'2719962977'</dd><dt>Dave Hayes</dt><dd>'7712773338'</dd><dt>Britney Stone</dt><dd>'2176728685'</dd><dt>Grace Thomas</dt><dd>'4747612996'</dd><dt>Rodney Hayes</dt><dd>'1999913571'</dd><dt>Cecil Carroll</dt><dd>'6855458548'</dd><dt>Chloe Parker</dt><dd>'4337314399'</dd><dt>Javier Mccoy</dt><dd>'8559251914'</dd><dt>Allie Romero</dt><dd>'3977435792'</dd><dt>Don Perry</dt><dd>'3684564218'</dd><dt>Janet White</dt><dd>'2931971171'</dd><dt>John Olson</dt><dd>'3334182462'</dd><dt>Greg Murphy</dt><dd>'9185549594'</dd><dt>Herman Bates</dt><dd>'4877764274'</dd></dl>\n"
],
"text/latex": [
"\\begin{description*}\n",
"\\item[Rosie Bowman] '6615439332'\n",
"\\item[Connor Knight] '9982919943'\n",
"\\item[Jackson Rice] '8712699959'\n",
"\\item[Gerry Graham] '9173869732'\n",
"\\item[Javier Griffin] '7856213414'\n",
"\\item[Katherine Frazier] '9764732656'\n",
"\\item[Wayne Mitchelle] '9389229535'\n",
"\\item[Linda Lane] '4831742356'\n",
"\\item[Erik Vargas] '9712597539'\n",
"\\item[Izzie Curtis] '8675747339'\n",
"\\item[Angela Wade] '5588312235'\n",
"\\item[Frederick Davies] '8212726576'\n",
"\\item[Leah Daniels] '1866817987'\n",
"\\item[Julie Clark] '7593953313'\n",
"\\item[Angela Olson] '7545216358'\n",
"\\item[Lance Fields] '7233578444'\n",
"\\item[Gabe Hudson] '4995975496'\n",
"\\item[Carolyn Mckinney] '2226228237'\n",
"\\item[Albert Evans] '8915525682'\n",
"\\item[Tracy Payne] '8675565482'\n",
"\\item[Elmer Williamson] '6143916348'\n",
"\\item[Marshall Diaz] '2327795536'\n",
"\\item[Andrea Berry] '3932358866'\n",
"\\item[Diane Hayes] '6127614281'\n",
"\\item[Jose Murphy] '4954311953'\n",
"\\item[Herman Miller] '9737313414'\n",
"\\item[Jennifer Gordon] '3568394793'\n",
"\\item[Tracey Ramirez] '6297979277'\n",
"\\item[Levi Harris] '4224592664'\n",
"\\item[Salvador Fletcher] '6142845797'\n",
"\\item[Isabella Holmes] '1724765495'\n",
"\\item[Dylan Carroll] '4741174722'\n",
"\\item[Claude Rose] '4923217947'\n",
"\\item[Brayden Fields] '3853314997'\n",
"\\item[Katie Marshall] '8222825122'\n",
"\\item[Suzanne Jennings] '6576943995'\n",
"\\item[Rosalyn Byrd] '7253581738'\n",
"\\item[Arnold Rogers] '2591732879'\n",
"\\item[Lisa Pena] '4471189654'\n",
"\\item[Avery Pena] '9566552291'\n",
"\\item[Karen Grant] '8264212844'\n",
"\\item[Edwin Wright] '5227394171'\n",
"\\item[Ashley James] '2625261646'\n",
"\\item[Arthur Austin] '5414736426'\n",
"\\item[Catherine Castillo] '9914781622'\n",
"\\item[Mary Kennedy] '6972144772'\n",
"\\item[Sophie Smith] '8378648123'\n",
"\\item[Austin Alvarez] '7554529522'\n",
"\\item[Roland Jimenez] '1732971876'\n",
"\\item[Mary Hale] '8994466533'\n",
"\\item[Paige Elliott] '1985127877'\n",
"\\item[Gabriel Ryan] '5153716534'\n",
"\\item[Mario Harvey] '6266137478'\n",
"\\item[Debra Lord] '5759231777'\n",
"\\item[Kim Clarke] '1112561989'\n",
"\\item[Jason Hoffman] '4356531274'\n",
"\\item[Alfredo Sims] '3325868858'\n",
"\\item[Susie Coleman] '3526347392'\n",
"\\item[Brennan Holt] '7559353559'\n",
"\\item[Bob Nguyen] '4296137972'\n",
"\\item[Josef Hanson] '7638259959'\n",
"\\item[Jerry Macrae] '1294779948'\n",
"\\item[Heather Watts] '4343452674'\n",
"\\item[Isabella Little] '8291167476'\n",
"\\item[Deborah Johnson] '6848854433'\n",
"\\item[Laura Ray] '7214313942'\n",
"\\item[Chad Sullivan] '7616634797'\n",
"\\item[Gabe Burton] '3357823729'\n",
"\\item[Suzy Edwards] '3115996814'\n",
"\\item[Sofia Cook] '8728786727'\n",
"\\item[Lillian Perkins] '1373463215'\n",
"\\item[Zander Lord] '2242251789'\n",
"\\item[Gerry May] '7673671557'\n",
"\\item[Callum Roberts] '1792536149'\n",
"\\item[Randall Davidson] '2342638893'\n",
"\\item[Carol Franklin] '4898626852'\n",
"\\item[Eugene Hunter] '5535845644'\n",
"\\item[Abbie Herrera] '7825426887'\n",
"\\item[George Riley] '9233283553'\n",
"\\item[Scarlett Moreno] '1279256655'\n",
"\\item[Janet Welch] '5245312375'\n",
"\\item[Vicky Bradley] '2896595195'\n",
"\\item[Walter Hawkins] '8794351787'\n",
"\\item[Jose Collins] '9529823429'\n",
"\\item[Greg Simmons] '2633693539'\n",
"\\item[Amy Richardson] '6525111453'\n",
"\\item[Kelly Foster] '2719962977'\n",
"\\item[Dave Hayes] '7712773338'\n",
"\\item[Britney Stone] '2176728685'\n",
"\\item[Grace Thomas] '4747612996'\n",
"\\item[Rodney Hayes] '1999913571'\n",
"\\item[Cecil Carroll] '6855458548'\n",
"\\item[Chloe Parker] '4337314399'\n",
"\\item[Javier Mccoy] '8559251914'\n",
"\\item[Allie Romero] '3977435792'\n",
"\\item[Don Perry] '3684564218'\n",
"\\item[Janet White] '2931971171'\n",
"\\item[John Olson] '3334182462'\n",
"\\item[Greg Murphy] '9185549594'\n",
"\\item[Herman Bates] '4877764274'\n",
"\\end{description*}\n"
],
"text/markdown": [
"Rosie Bowman\n",
": '6615439332'Connor Knight\n",
": '9982919943'Jackson Rice\n",
": '8712699959'Gerry Graham\n",
": '9173869732'Javier Griffin\n",
": '7856213414'Katherine Frazier\n",
": '9764732656'Wayne Mitchelle\n",
": '9389229535'Linda Lane\n",
": '4831742356'Erik Vargas\n",
": '9712597539'Izzie Curtis\n",
": '8675747339'Angela Wade\n",
": '5588312235'Frederick Davies\n",
": '8212726576'Leah Daniels\n",
": '1866817987'Julie Clark\n",
": '7593953313'Angela Olson\n",
": '7545216358'Lance Fields\n",
": '7233578444'Gabe Hudson\n",
": '4995975496'Carolyn Mckinney\n",
": '2226228237'Albert Evans\n",
": '8915525682'Tracy Payne\n",
": '8675565482'Elmer Williamson\n",
": '6143916348'Marshall Diaz\n",
": '2327795536'Andrea Berry\n",
": '3932358866'Diane Hayes\n",
": '6127614281'Jose Murphy\n",
": '4954311953'Herman Miller\n",
": '9737313414'Jennifer Gordon\n",
": '3568394793'Tracey Ramirez\n",
": '6297979277'Levi Harris\n",
": '4224592664'Salvador Fletcher\n",
": '6142845797'Isabella Holmes\n",
": '1724765495'Dylan Carroll\n",
": '4741174722'Claude Rose\n",
": '4923217947'Brayden Fields\n",
": '3853314997'Katie Marshall\n",
": '8222825122'Suzanne Jennings\n",
": '6576943995'Rosalyn Byrd\n",
": '7253581738'Arnold Rogers\n",
": '2591732879'Lisa Pena\n",
": '4471189654'Avery Pena\n",
": '9566552291'Karen Grant\n",
": '8264212844'Edwin Wright\n",
": '5227394171'Ashley James\n",
": '2625261646'Arthur Austin\n",
": '5414736426'Catherine Castillo\n",
": '9914781622'Mary Kennedy\n",
": '6972144772'Sophie Smith\n",
": '8378648123'Austin Alvarez\n",
": '7554529522'Roland Jimenez\n",
": '1732971876'Mary Hale\n",
": '8994466533'Paige Elliott\n",
": '1985127877'Gabriel Ryan\n",
": '5153716534'Mario Harvey\n",
": '6266137478'Debra Lord\n",
": '5759231777'Kim Clarke\n",
": '1112561989'Jason Hoffman\n",
": '4356531274'Alfredo Sims\n",
": '3325868858'Susie Coleman\n",
": '3526347392'Brennan Holt\n",
": '7559353559'Bob Nguyen\n",
": '4296137972'Josef Hanson\n",
": '7638259959'Jerry Macrae\n",
": '1294779948'Heather Watts\n",
": '4343452674'Isabella Little\n",
": '8291167476'Deborah Johnson\n",
": '6848854433'Laura Ray\n",
": '7214313942'Chad Sullivan\n",
": '7616634797'Gabe Burton\n",
": '3357823729'Suzy Edwards\n",
": '3115996814'Sofia Cook\n",
": '8728786727'Lillian Perkins\n",
": '1373463215'Zander Lord\n",
": '2242251789'Gerry May\n",
": '7673671557'Callum Roberts\n",
": '1792536149'Randall Davidson\n",
": '2342638893'Carol Franklin\n",
": '4898626852'Eugene Hunter\n",
": '5535845644'Abbie Herrera\n",
": '7825426887'George Riley\n",
": '9233283553'Scarlett Moreno\n",
": '1279256655'Janet Welch\n",
": '5245312375'Vicky Bradley\n",
": '2896595195'Walter Hawkins\n",
": '8794351787'Jose Collins\n",
": '9529823429'Greg Simmons\n",
": '2633693539'Amy Richardson\n",
": '6525111453'Kelly Foster\n",
": '2719962977'Dave Hayes\n",
": '7712773338'Britney Stone\n",
": '2176728685'Grace Thomas\n",
": '4747612996'Rodney Hayes\n",
": '1999913571'Cecil Carroll\n",
": '6855458548'Chloe Parker\n",
": '4337314399'Javier Mccoy\n",
": '8559251914'Allie Romero\n",
": '3977435792'Don Perry\n",
": '3684564218'Janet White\n",
": '2931971171'John Olson\n",
": '3334182462'Greg Murphy\n",
": '9185549594'Herman Bates\n",
": '4877764274'\n",
"\n"
],
"text/plain": [
" Rosie Bowman Connor Knight Jackson Rice Gerry Graham \n",
" \"6615439332\" \"9982919943\" \"8712699959\" \"9173869732\" \n",
" Javier Griffin Katherine Frazier Wayne Mitchelle Linda Lane \n",
" \"7856213414\" \"9764732656\" \"9389229535\" \"4831742356\" \n",
" Erik Vargas Izzie Curtis Angela Wade Frederick Davies \n",
" \"9712597539\" \"8675747339\" \"5588312235\" \"8212726576\" \n",
" Leah Daniels Julie Clark Angela Olson Lance Fields \n",
" \"1866817987\" \"7593953313\" \"7545216358\" \"7233578444\" \n",
" Gabe Hudson Carolyn Mckinney Albert Evans Tracy Payne \n",
" \"4995975496\" \"2226228237\" \"8915525682\" \"8675565482\" \n",
" Elmer Williamson Marshall Diaz Andrea Berry Diane Hayes \n",
" \"6143916348\" \"2327795536\" \"3932358866\" \"6127614281\" \n",
" Jose Murphy Herman Miller Jennifer Gordon Tracey Ramirez \n",
" \"4954311953\" \"9737313414\" \"3568394793\" \"6297979277\" \n",
" Levi Harris Salvador Fletcher Isabella Holmes Dylan Carroll \n",
" \"4224592664\" \"6142845797\" \"1724765495\" \"4741174722\" \n",
" Claude Rose Brayden Fields Katie Marshall Suzanne Jennings \n",
" \"4923217947\" \"3853314997\" \"8222825122\" \"6576943995\" \n",
" Rosalyn Byrd Arnold Rogers Lisa Pena Avery Pena \n",
" \"7253581738\" \"2591732879\" \"4471189654\" \"9566552291\" \n",
" Karen Grant Edwin Wright Ashley James Arthur Austin \n",
" \"8264212844\" \"5227394171\" \"2625261646\" \"5414736426\" \n",
"Catherine Castillo Mary Kennedy Sophie Smith Austin Alvarez \n",
" \"9914781622\" \"6972144772\" \"8378648123\" \"7554529522\" \n",
" Roland Jimenez Mary Hale Paige Elliott Gabriel Ryan \n",
" \"1732971876\" \"8994466533\" \"1985127877\" \"5153716534\" \n",
" Mario Harvey Debra Lord Kim Clarke Jason Hoffman \n",
" \"6266137478\" \"5759231777\" \"1112561989\" \"4356531274\" \n",
" Alfredo Sims Susie Coleman Brennan Holt Bob Nguyen \n",
" \"3325868858\" \"3526347392\" \"7559353559\" \"4296137972\" \n",
" Josef Hanson Jerry Macrae Heather Watts Isabella Little \n",
" \"7638259959\" \"1294779948\" \"4343452674\" \"8291167476\" \n",
" Deborah Johnson Laura Ray Chad Sullivan Gabe Burton \n",
" \"6848854433\" \"7214313942\" \"7616634797\" \"3357823729\" \n",
" Suzy Edwards Sofia Cook Lillian Perkins Zander Lord \n",
" \"3115996814\" \"8728786727\" \"1373463215\" \"2242251789\" \n",
" Gerry May Callum Roberts Randall Davidson Carol Franklin \n",
" \"7673671557\" \"1792536149\" \"2342638893\" \"4898626852\" \n",
" Eugene Hunter Abbie Herrera George Riley Scarlett Moreno \n",
" \"5535845644\" \"7825426887\" \"9233283553\" \"1279256655\" \n",
" Janet Welch Vicky Bradley Walter Hawkins Jose Collins \n",
" \"5245312375\" \"2896595195\" \"8794351787\" \"9529823429\" \n",
" Greg Simmons Amy Richardson Kelly Foster Dave Hayes \n",
" \"2633693539\" \"6525111453\" \"2719962977\" \"7712773338\" \n",
" Britney Stone Grace Thomas Rodney Hayes Cecil Carroll \n",
" \"2176728685\" \"4747612996\" \"1999913571\" \"6855458548\" \n",
" Chloe Parker Javier Mccoy Allie Romero Don Perry \n",
" \"4337314399\" \"8559251914\" \"3977435792\" \"3684564218\" \n",
" Janet White John Olson Greg Murphy Herman Bates \n",
" \"2931971171\" \"3334182462\" \"9185549594\" \"4877764274\" "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"phone_book <- phone_nums\n",
"names(phone_book) <- people_names\n",
"phone_book"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"What was Jose Murphy's number again?"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<strong>Jose Murphy:</strong> '4954311953'"
],
"text/latex": [
"\\textbf{Jose Murphy:} '4954311953'"
],
"text/markdown": [
"**Jose Murphy:** '4954311953'"
],
"text/plain": [
" Jose Murphy \n",
"\"4954311953\" "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"phone_book[\"Jose Murphy\"]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And Susie Coleman's?"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<strong>Susie Coleman:</strong> '3526347392'"
],
"text/latex": [
"\\textbf{Susie Coleman:} '3526347392'"
],
"text/markdown": [
"**Susie Coleman:** '3526347392'"
],
"text/plain": [
"Susie Coleman \n",
" \"3526347392\" "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"phone_book[\"Susie Coleman\"]"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"R version 3.5.1 (2018-07-02)\n",
"Platform: x86_64-conda_cos6-linux-gnu (64-bit)\n",
"Running under: Debian GNU/Linux 10 (buster)\n",
"\n",
"Matrix products: default\n",
"BLAS/LAPACK: /home/jupyterlab/conda/envs/r/lib/R/lib/libRlapack.so\n",
"\n",
"locale:\n",
" [1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8 \n",
" [4] LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8 \n",
" [7] LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C \n",
"[10] LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C \n",
"\n",
"attached base packages:\n",
"[1] stats graphics grDevices utils datasets methods base \n",
"\n",
"other attached packages:\n",
"[1] randNames_0.2.3\n",
"\n",
"loaded via a namespace (and not attached):\n",
" [1] Rcpp_1.0.4.6 digest_0.6.25 crayon_1.3.4 IRdisplay_0.7.0\n",
" [5] R6_2.4.1 repr_1.1.0 lifecycle_0.2.0 jsonlite_1.6.1 \n",
" [9] magrittr_1.5 evaluate_0.14 pillar_1.4.3 httr_1.4.1 \n",
"[13] rlang_0.4.5 curl_4.3 uuid_0.1-4 vctrs_0.2.4 \n",
"[17] ellipsis_0.3.0 IRkernel_0.8.12 tools_3.5.1 glue_1.4.0 \n",
"[21] compiler_3.5.1 pkgconfig_2.0.3 base64enc_0.1-3 htmltools_0.4.0\n",
"[25] pbdZMQ_0.3-3 tibble_3.0.1 "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"sessionInfo()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "R",
"language": "R",
"name": "conda-env-r-r"
},
"language_info": {
"codemirror_mode": "r",
"file_extension": ".r",
"mimetype": "text/x-r-source",
"name": "R",
"pygments_lexer": "r",
"version": "3.5.1"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment