{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "0a2e54e4",
"metadata": {
"tags": [
"remove-cell"
]
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Registered S3 methods overwritten by 'ggplot2':\n",
" method from \n",
" [.quosures rlang\n",
" c.quosures rlang\n",
" print.quosures rlang\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Registered S3 method overwritten by 'rvest':\n",
" method from\n",
" read_xml.response xml2\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"-- Attaching packages --------------------------------------- tidyverse 1.2.1 --\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"v ggplot2 3.1.1 v purrr 0.3.2 \n",
"v tibble 2.1.1 v dplyr 0.8.0.1\n",
"v tidyr 0.8.3 v stringr 1.4.0 \n",
"v readr 1.3.1 v forcats 0.4.0 \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"-- Conflicts ------------------------------------------ tidyverse_conflicts() --\n",
"x dplyr::filter() masks stats::filter()\n",
"x dplyr::lag() masks stats::lag()\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Parsed with column specification:\n",
"cols(\n",
" ID = col_double(),\n",
" Name = col_character(),\n",
" Gender = col_character(),\n",
" Age = col_double(),\n",
" Rating = col_double(),\n",
" Degree = col_character(),\n",
" Start_Date = col_character(),\n",
" Retired = col_logical(),\n",
" Division = col_character(),\n",
" Salary = col_character()\n",
")\n"
]
}
],
"source": [
"library(tidyverse)\n",
"employees <- read_csv(\"../../_build/data/employee_data.csv\")\n",
"employees$Salary <- parse_number(employees$Salary)\n",
"employees$Start_Date <- parse_date(employees$Start_Date, format = \"%m/%d/%Y\")"
]
},
{
"cell_type": "markdown",
"id": "c4a451d7",
"metadata": {},
"source": [
"# Sorting Data\n",
"\n",
"Often you would like to sort your data based on one or more of the columns in your data set. This can be done using the `arrange()` function, which uses the following syntax:\n",
"\n",
"```{admonition} Syntax\n",
"`tidyverse::arrange(df, var1, var2, var3, ...)`\n",
"+ *Required arguments*\n",
" - `df`: The tibble (data frame) with the data you would like to sort. \n",
" - `var1`: The name of the column to use to sort the data.\n",
"+ *Optional arguments*\n",
" - `var2, var3, ...`: The name of additional columns to use to sort the data. When multiple columns are specified, each additional column is used to break ties in the preceding column. \n",
"```\n",
"\n",
"By default, `arrange()` sorts `numeric` variables from smallest to largest and `character` variables alphabetically. You can reverse the order of the sort by surrounding the column name with `desc()` in the function call.\n",
"\n",
"First, let's create a new version of the data frame called `employeesSortedAge`, with the employees sorted from youngest to oldest."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "f4ab9b82",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"ID | Name | Gender | Age | Rating | Degree | Start_Date | Retired | Division | Salary |
\n",
"\n",
"\t7068 | Dimas, Roman | Male | 25 | 8 | High School | 2017-02-23 | FALSE | Operations | 84252 |
\n",
"\t5464 | al-Pirani, Rajab | Male | 25 | 3 | Associate's | 2016-02-23 | FALSE | Operations | 37907 |
\n",
"\t7910 | Hopper, Summer | Female | 25 | 7 | Bachelor's | 2017-02-23 | FALSE | Engineering | 100688 |
\n",
"\t6784 | al-Siddique, Zaitoona | Female | 25 | 4 | Master's | 2015-02-23 | FALSE | Human Resources | 127618 |
\n",
"\t3240 | Steggall, Shai | Female | 25 | 7 | Master's | 2017-02-23 | FALSE | Operations | 117062 |
\n",
"\t1413 | Tanner, Sean | Male | 25 | 2 | Associate's | 2016-02-23 | FALSE | Operations | 61869 |
\n",
"\n",
"
\n"
],
"text/latex": [
"\\begin{tabular}{r|llllllllll}\n",
" ID & Name & Gender & Age & Rating & Degree & Start\\_Date & Retired & Division & Salary\\\\\n",
"\\hline\n",
"\t 7068 & Dimas, Roman & Male & 25 & 8 & High School & 2017-02-23 & FALSE & Operations & 84252 \\\\\n",
"\t 5464 & al-Pirani, Rajab & Male & 25 & 3 & Associate's & 2016-02-23 & FALSE & Operations & 37907 \\\\\n",
"\t 7910 & Hopper, Summer & Female & 25 & 7 & Bachelor's & 2017-02-23 & FALSE & Engineering & 100688 \\\\\n",
"\t 6784 & al-Siddique, Zaitoona & Female & 25 & 4 & Master's & 2015-02-23 & FALSE & Human Resources & 127618 \\\\\n",
"\t 3240 & Steggall, Shai & Female & 25 & 7 & Master's & 2017-02-23 & FALSE & Operations & 117062 \\\\\n",
"\t 1413 & Tanner, Sean & Male & 25 & 2 & Associate's & 2016-02-23 & FALSE & Operations & 61869 \\\\\n",
"\\end{tabular}\n"
],
"text/markdown": [
"\n",
"| ID | Name | Gender | Age | Rating | Degree | Start_Date | Retired | Division | Salary |\n",
"|---|---|---|---|---|---|---|---|---|---|\n",
"| 7068 | Dimas, Roman | Male | 25 | 8 | High School | 2017-02-23 | FALSE | Operations | 84252 |\n",
"| 5464 | al-Pirani, Rajab | Male | 25 | 3 | Associate's | 2016-02-23 | FALSE | Operations | 37907 |\n",
"| 7910 | Hopper, Summer | Female | 25 | 7 | Bachelor's | 2017-02-23 | FALSE | Engineering | 100688 |\n",
"| 6784 | al-Siddique, Zaitoona | Female | 25 | 4 | Master's | 2015-02-23 | FALSE | Human Resources | 127618 |\n",
"| 3240 | Steggall, Shai | Female | 25 | 7 | Master's | 2017-02-23 | FALSE | Operations | 117062 |\n",
"| 1413 | Tanner, Sean | Male | 25 | 2 | Associate's | 2016-02-23 | FALSE | Operations | 61869 |\n",
"\n"
],
"text/plain": [
" ID Name Gender Age Rating Degree Start_Date Retired\n",
"1 7068 Dimas, Roman Male 25 8 High School 2017-02-23 FALSE \n",
"2 5464 al-Pirani, Rajab Male 25 3 Associate's 2016-02-23 FALSE \n",
"3 7910 Hopper, Summer Female 25 7 Bachelor's 2017-02-23 FALSE \n",
"4 6784 al-Siddique, Zaitoona Female 25 4 Master's 2015-02-23 FALSE \n",
"5 3240 Steggall, Shai Female 25 7 Master's 2017-02-23 FALSE \n",
"6 1413 Tanner, Sean Male 25 2 Associate's 2016-02-23 FALSE \n",
" Division Salary\n",
"1 Operations 84252\n",
"2 Operations 37907\n",
"3 Engineering 100688\n",
"4 Human Resources 127618\n",
"5 Operations 117062\n",
"6 Operations 61869"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"employeesSortedAge <- arrange(employees, Age)\n",
"head(employeesSortedAge)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "8772af8c",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"ID | Name | Gender | Age | Rating | Degree | Start_Date | Retired | Division | Salary |
\n",
"\n",
"\t6798 | Werkele, Jakob | Male | 65 | 7 | Ph.D | 1976-02-23 | TRUE | Engineering | NA |
\n",
"\t6291 | Anderson, Collyn | Male | 65 | 6 | High School | 1977-02-23 | FALSE | Operations | 179634 |
\n",
"\t8481 | Phillips, Jasmyn | Female | 65 | 5 | High School | 1975-02-23 | TRUE | Sales | NA |
\n",
"\t4600 | Olivas, Julian | Male | 65 | 2 | Ph.D | 1976-02-23 | FALSE | Engineering | 204576 |
\n",
"\t6777 | Mortimer, Kendall | Female | 65 | 7 | Master's | 1977-02-23 | FALSE | Corporate | 248925 |
\n",
"\t2924 | Mills, Tasia | Female | 65 | 8 | High School | 1977-02-23 | FALSE | Operations | 138212 |
\n",
"\n",
"
\n"
],
"text/latex": [
"\\begin{tabular}{r|llllllllll}\n",
" ID & Name & Gender & Age & Rating & Degree & Start\\_Date & Retired & Division & Salary\\\\\n",
"\\hline\n",
"\t 6798 & Werkele, Jakob & Male & 65 & 7 & Ph.D & 1976-02-23 & TRUE & Engineering & NA \\\\\n",
"\t 6291 & Anderson, Collyn & Male & 65 & 6 & High School & 1977-02-23 & FALSE & Operations & 179634 \\\\\n",
"\t 8481 & Phillips, Jasmyn & Female & 65 & 5 & High School & 1975-02-23 & TRUE & Sales & NA \\\\\n",
"\t 4600 & Olivas, Julian & Male & 65 & 2 & Ph.D & 1976-02-23 & FALSE & Engineering & 204576 \\\\\n",
"\t 6777 & Mortimer, Kendall & Female & 65 & 7 & Master's & 1977-02-23 & FALSE & Corporate & 248925 \\\\\n",
"\t 2924 & Mills, Tasia & Female & 65 & 8 & High School & 1977-02-23 & FALSE & Operations & 138212 \\\\\n",
"\\end{tabular}\n"
],
"text/markdown": [
"\n",
"| ID | Name | Gender | Age | Rating | Degree | Start_Date | Retired | Division | Salary |\n",
"|---|---|---|---|---|---|---|---|---|---|\n",
"| 6798 | Werkele, Jakob | Male | 65 | 7 | Ph.D | 1976-02-23 | TRUE | Engineering | NA |\n",
"| 6291 | Anderson, Collyn | Male | 65 | 6 | High School | 1977-02-23 | FALSE | Operations | 179634 |\n",
"| 8481 | Phillips, Jasmyn | Female | 65 | 5 | High School | 1975-02-23 | TRUE | Sales | NA |\n",
"| 4600 | Olivas, Julian | Male | 65 | 2 | Ph.D | 1976-02-23 | FALSE | Engineering | 204576 |\n",
"| 6777 | Mortimer, Kendall | Female | 65 | 7 | Master's | 1977-02-23 | FALSE | Corporate | 248925 |\n",
"| 2924 | Mills, Tasia | Female | 65 | 8 | High School | 1977-02-23 | FALSE | Operations | 138212 |\n",
"\n"
],
"text/plain": [
" ID Name Gender Age Rating Degree Start_Date Retired\n",
"1 6798 Werkele, Jakob Male 65 7 Ph.D 1976-02-23 TRUE \n",
"2 6291 Anderson, Collyn Male 65 6 High School 1977-02-23 FALSE \n",
"3 8481 Phillips, Jasmyn Female 65 5 High School 1975-02-23 TRUE \n",
"4 4600 Olivas, Julian Male 65 2 Ph.D 1976-02-23 FALSE \n",
"5 6777 Mortimer, Kendall Female 65 7 Master's 1977-02-23 FALSE \n",
"6 2924 Mills, Tasia Female 65 8 High School 1977-02-23 FALSE \n",
" Division Salary\n",
"1 Engineering NA\n",
"2 Operations 179634\n",
"3 Sales NA\n",
"4 Engineering 204576\n",
"5 Corporate 248925\n",
"6 Operations 138212"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"tail(employeesSortedAge)"
]
},
{
"cell_type": "markdown",
"id": "7c8746d3",
"metadata": {},
"source": [
"We can instead sort the data from oldest to youngest by adding `desc()` around `Age`:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "927fe0c5",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"ID | Name | Gender | Age | Rating | Degree | Start_Date | Retired | Division | Salary |
\n",
"\n",
"\t8060 | al-Morad, Mastoor | Male | 65 | 8 | Ph.D | 1977-02-23 | FALSE | Corporate | 213381 |
\n",
"\t9545 | Lloyd, Devante | Male | 65 | 9 | Bachelor's | 1974-02-23 | FALSE | Accounting | 243326 |
\n",
"\t7305 | Law, Charisma | Female | 65 | 8 | Associate's | 1976-02-23 | FALSE | Human Resources | 214788 |
\n",
"\t4141 | Herrera, Yarabbi | Female | 65 | 8 | High School | 1975-02-23 | FALSE | Operations | 143728 |
\n",
"\t2559 | Holiday, Emma | Female | 65 | 7 | Bachelor's | 1975-02-23 | TRUE | Operations | NA |
\n",
"\t4407 | Ross, Caitlyn | Female | 65 | 7 | Bachelor's | 1975-02-23 | TRUE | Corporate | NA |
\n",
"\n",
"
\n"
],
"text/latex": [
"\\begin{tabular}{r|llllllllll}\n",
" ID & Name & Gender & Age & Rating & Degree & Start\\_Date & Retired & Division & Salary\\\\\n",
"\\hline\n",
"\t 8060 & al-Morad, Mastoor & Male & 65 & 8 & Ph.D & 1977-02-23 & FALSE & Corporate & 213381 \\\\\n",
"\t 9545 & Lloyd, Devante & Male & 65 & 9 & Bachelor's & 1974-02-23 & FALSE & Accounting & 243326 \\\\\n",
"\t 7305 & Law, Charisma & Female & 65 & 8 & Associate's & 1976-02-23 & FALSE & Human Resources & 214788 \\\\\n",
"\t 4141 & Herrera, Yarabbi & Female & 65 & 8 & High School & 1975-02-23 & FALSE & Operations & 143728 \\\\\n",
"\t 2559 & Holiday, Emma & Female & 65 & 7 & Bachelor's & 1975-02-23 & TRUE & Operations & NA \\\\\n",
"\t 4407 & Ross, Caitlyn & Female & 65 & 7 & Bachelor's & 1975-02-23 & TRUE & Corporate & NA \\\\\n",
"\\end{tabular}\n"
],
"text/markdown": [
"\n",
"| ID | Name | Gender | Age | Rating | Degree | Start_Date | Retired | Division | Salary |\n",
"|---|---|---|---|---|---|---|---|---|---|\n",
"| 8060 | al-Morad, Mastoor | Male | 65 | 8 | Ph.D | 1977-02-23 | FALSE | Corporate | 213381 |\n",
"| 9545 | Lloyd, Devante | Male | 65 | 9 | Bachelor's | 1974-02-23 | FALSE | Accounting | 243326 |\n",
"| 7305 | Law, Charisma | Female | 65 | 8 | Associate's | 1976-02-23 | FALSE | Human Resources | 214788 |\n",
"| 4141 | Herrera, Yarabbi | Female | 65 | 8 | High School | 1975-02-23 | FALSE | Operations | 143728 |\n",
"| 2559 | Holiday, Emma | Female | 65 | 7 | Bachelor's | 1975-02-23 | TRUE | Operations | NA |\n",
"| 4407 | Ross, Caitlyn | Female | 65 | 7 | Bachelor's | 1975-02-23 | TRUE | Corporate | NA |\n",
"\n"
],
"text/plain": [
" ID Name Gender Age Rating Degree Start_Date Retired\n",
"1 8060 al-Morad, Mastoor Male 65 8 Ph.D 1977-02-23 FALSE \n",
"2 9545 Lloyd, Devante Male 65 9 Bachelor's 1974-02-23 FALSE \n",
"3 7305 Law, Charisma Female 65 8 Associate's 1976-02-23 FALSE \n",
"4 4141 Herrera, Yarabbi Female 65 8 High School 1975-02-23 FALSE \n",
"5 2559 Holiday, Emma Female 65 7 Bachelor's 1975-02-23 TRUE \n",
"6 4407 Ross, Caitlyn Female 65 7 Bachelor's 1975-02-23 TRUE \n",
" Division Salary\n",
"1 Corporate 213381\n",
"2 Accounting 243326\n",
"3 Human Resources 214788\n",
"4 Operations 143728\n",
"5 Operations NA\n",
"6 Corporate NA"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"employeesSortedAgeDesc <- arrange(employees, desc(Age))\n",
"head(employeesSortedAgeDesc)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "84021529",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"ID | Name | Gender | Age | Rating | Degree | Start_Date | Retired | Division | Salary |
\n",
"\n",
"\t1413 | Tanner, Sean | Male | 25 | 2 | Associate's | 2016-02-23 | FALSE | Operations | 61869 |
\n",
"\t8324 | Bancroft, Isaiah | Male | 25 | 7 | Master's | 2017-02-23 | FALSE | Corporate | 135935 |
\n",
"\t1230 | Kirgis, Arissa | Female | 25 | 8 | Bachelor's | 2015-02-23 | FALSE | Operations | 113573 |
\n",
"\t6308 | Barnett, Marquise | Male | 25 | 8 | Master's | 2016-02-23 | FALSE | Operations | 103798 |
\n",
"\t3241 | Byrd, Sydny | Female | 25 | 6 | Ph.D | 2016-02-23 | FALSE | Engineering | 126366 |
\n",
"\t9249 | Lopez, Karissa | Female | 25 | 8 | Associate's | 2016-02-23 | FALSE | Sales | 75689 |
\n",
"\n",
"
\n"
],
"text/latex": [
"\\begin{tabular}{r|llllllllll}\n",
" ID & Name & Gender & Age & Rating & Degree & Start\\_Date & Retired & Division & Salary\\\\\n",
"\\hline\n",
"\t 1413 & Tanner, Sean & Male & 25 & 2 & Associate's & 2016-02-23 & FALSE & Operations & 61869 \\\\\n",
"\t 8324 & Bancroft, Isaiah & Male & 25 & 7 & Master's & 2017-02-23 & FALSE & Corporate & 135935 \\\\\n",
"\t 1230 & Kirgis, Arissa & Female & 25 & 8 & Bachelor's & 2015-02-23 & FALSE & Operations & 113573 \\\\\n",
"\t 6308 & Barnett, Marquise & Male & 25 & 8 & Master's & 2016-02-23 & FALSE & Operations & 103798 \\\\\n",
"\t 3241 & Byrd, Sydny & Female & 25 & 6 & Ph.D & 2016-02-23 & FALSE & Engineering & 126366 \\\\\n",
"\t 9249 & Lopez, Karissa & Female & 25 & 8 & Associate's & 2016-02-23 & FALSE & Sales & 75689 \\\\\n",
"\\end{tabular}\n"
],
"text/markdown": [
"\n",
"| ID | Name | Gender | Age | Rating | Degree | Start_Date | Retired | Division | Salary |\n",
"|---|---|---|---|---|---|---|---|---|---|\n",
"| 1413 | Tanner, Sean | Male | 25 | 2 | Associate's | 2016-02-23 | FALSE | Operations | 61869 |\n",
"| 8324 | Bancroft, Isaiah | Male | 25 | 7 | Master's | 2017-02-23 | FALSE | Corporate | 135935 |\n",
"| 1230 | Kirgis, Arissa | Female | 25 | 8 | Bachelor's | 2015-02-23 | FALSE | Operations | 113573 |\n",
"| 6308 | Barnett, Marquise | Male | 25 | 8 | Master's | 2016-02-23 | FALSE | Operations | 103798 |\n",
"| 3241 | Byrd, Sydny | Female | 25 | 6 | Ph.D | 2016-02-23 | FALSE | Engineering | 126366 |\n",
"| 9249 | Lopez, Karissa | Female | 25 | 8 | Associate's | 2016-02-23 | FALSE | Sales | 75689 |\n",
"\n"
],
"text/plain": [
" ID Name Gender Age Rating Degree Start_Date Retired\n",
"1 1413 Tanner, Sean Male 25 2 Associate's 2016-02-23 FALSE \n",
"2 8324 Bancroft, Isaiah Male 25 7 Master's 2017-02-23 FALSE \n",
"3 1230 Kirgis, Arissa Female 25 8 Bachelor's 2015-02-23 FALSE \n",
"4 6308 Barnett, Marquise Male 25 8 Master's 2016-02-23 FALSE \n",
"5 3241 Byrd, Sydny Female 25 6 Ph.D 2016-02-23 FALSE \n",
"6 9249 Lopez, Karissa Female 25 8 Associate's 2016-02-23 FALSE \n",
" Division Salary\n",
"1 Operations 61869\n",
"2 Corporate 135935\n",
"3 Operations 113573\n",
"4 Operations 103798\n",
"5 Engineering 126366\n",
"6 Sales 75689"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"tail(employeesSortedAgeDesc)"
]
},
{
"cell_type": "markdown",
"id": "13aa9187",
"metadata": {},
"source": [
"Now imagine that we wanted to perform a multi-level sort, where we first sort the employees from oldest to youngest, and then within each age sort the names alphabetically. We can do this by adding the `Name` column to our function call:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "5389e54a",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"ID | Name | Gender | Age | Rating | Degree | Start_Date | Retired | Division | Salary |
\n",
"\n",
"\t8060 | al-Morad, Mastoor | Male | 65 | 8 | Ph.D | 1977-02-23 | FALSE | Corporate | 213381 |
\n",
"\t6291 | Anderson, Collyn | Male | 65 | 6 | High School | 1977-02-23 | FALSE | Operations | 179634 |
\n",
"\t3661 | el-Meskin, Asad | Male | 65 | 9 | Bachelor's | 1977-02-23 | FALSE | Engineering | 177504 |
\n",
"\t5245 | Gowen, Hannah | Female | 65 | 7 | Bachelor's | 1975-02-23 | FALSE | Accounting | 191765 |
\n",
"\t4141 | Herrera, Yarabbi | Female | 65 | 8 | High School | 1975-02-23 | FALSE | Operations | 143728 |
\n",
"\t2559 | Holiday, Emma | Female | 65 | 7 | Bachelor's | 1975-02-23 | TRUE | Operations | NA |
\n",
"\n",
"
\n"
],
"text/latex": [
"\\begin{tabular}{r|llllllllll}\n",
" ID & Name & Gender & Age & Rating & Degree & Start\\_Date & Retired & Division & Salary\\\\\n",
"\\hline\n",
"\t 8060 & al-Morad, Mastoor & Male & 65 & 8 & Ph.D & 1977-02-23 & FALSE & Corporate & 213381 \\\\\n",
"\t 6291 & Anderson, Collyn & Male & 65 & 6 & High School & 1977-02-23 & FALSE & Operations & 179634 \\\\\n",
"\t 3661 & el-Meskin, Asad & Male & 65 & 9 & Bachelor's & 1977-02-23 & FALSE & Engineering & 177504 \\\\\n",
"\t 5245 & Gowen, Hannah & Female & 65 & 7 & Bachelor's & 1975-02-23 & FALSE & Accounting & 191765 \\\\\n",
"\t 4141 & Herrera, Yarabbi & Female & 65 & 8 & High School & 1975-02-23 & FALSE & Operations & 143728 \\\\\n",
"\t 2559 & Holiday, Emma & Female & 65 & 7 & Bachelor's & 1975-02-23 & TRUE & Operations & NA \\\\\n",
"\\end{tabular}\n"
],
"text/markdown": [
"\n",
"| ID | Name | Gender | Age | Rating | Degree | Start_Date | Retired | Division | Salary |\n",
"|---|---|---|---|---|---|---|---|---|---|\n",
"| 8060 | al-Morad, Mastoor | Male | 65 | 8 | Ph.D | 1977-02-23 | FALSE | Corporate | 213381 |\n",
"| 6291 | Anderson, Collyn | Male | 65 | 6 | High School | 1977-02-23 | FALSE | Operations | 179634 |\n",
"| 3661 | el-Meskin, Asad | Male | 65 | 9 | Bachelor's | 1977-02-23 | FALSE | Engineering | 177504 |\n",
"| 5245 | Gowen, Hannah | Female | 65 | 7 | Bachelor's | 1975-02-23 | FALSE | Accounting | 191765 |\n",
"| 4141 | Herrera, Yarabbi | Female | 65 | 8 | High School | 1975-02-23 | FALSE | Operations | 143728 |\n",
"| 2559 | Holiday, Emma | Female | 65 | 7 | Bachelor's | 1975-02-23 | TRUE | Operations | NA |\n",
"\n"
],
"text/plain": [
" ID Name Gender Age Rating Degree Start_Date Retired\n",
"1 8060 al-Morad, Mastoor Male 65 8 Ph.D 1977-02-23 FALSE \n",
"2 6291 Anderson, Collyn Male 65 6 High School 1977-02-23 FALSE \n",
"3 3661 el-Meskin, Asad Male 65 9 Bachelor's 1977-02-23 FALSE \n",
"4 5245 Gowen, Hannah Female 65 7 Bachelor's 1975-02-23 FALSE \n",
"5 4141 Herrera, Yarabbi Female 65 8 High School 1975-02-23 FALSE \n",
"6 2559 Holiday, Emma Female 65 7 Bachelor's 1975-02-23 TRUE \n",
" Division Salary\n",
"1 Corporate 213381\n",
"2 Operations 179634\n",
"3 Engineering 177504\n",
"4 Accounting 191765\n",
"5 Operations 143728\n",
"6 Operations NA"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"employeesSortedAgeDescName <- arrange(employees, desc(Age), Name)\n",
"head(employeesSortedAgeDescName)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "d4ad9d7a",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"ID | Name | Gender | Age | Rating | Degree | Start_Date | Retired | Division | Salary |
\n",
"\n",
"\t7068 | Dimas, Roman | Male | 25 | 8 | High School | 2017-02-23 | FALSE | Operations | 84252 |
\n",
"\t7910 | Hopper, Summer | Female | 25 | 7 | Bachelor's | 2017-02-23 | FALSE | Engineering | 100688 |
\n",
"\t1230 | Kirgis, Arissa | Female | 25 | 8 | Bachelor's | 2015-02-23 | FALSE | Operations | 113573 |
\n",
"\t9249 | Lopez, Karissa | Female | 25 | 8 | Associate's | 2016-02-23 | FALSE | Sales | 75689 |
\n",
"\t3240 | Steggall, Shai | Female | 25 | 7 | Master's | 2017-02-23 | FALSE | Operations | 117062 |
\n",
"\t1413 | Tanner, Sean | Male | 25 | 2 | Associate's | 2016-02-23 | FALSE | Operations | 61869 |
\n",
"\n",
"
\n"
],
"text/latex": [
"\\begin{tabular}{r|llllllllll}\n",
" ID & Name & Gender & Age & Rating & Degree & Start\\_Date & Retired & Division & Salary\\\\\n",
"\\hline\n",
"\t 7068 & Dimas, Roman & Male & 25 & 8 & High School & 2017-02-23 & FALSE & Operations & 84252 \\\\\n",
"\t 7910 & Hopper, Summer & Female & 25 & 7 & Bachelor's & 2017-02-23 & FALSE & Engineering & 100688 \\\\\n",
"\t 1230 & Kirgis, Arissa & Female & 25 & 8 & Bachelor's & 2015-02-23 & FALSE & Operations & 113573 \\\\\n",
"\t 9249 & Lopez, Karissa & Female & 25 & 8 & Associate's & 2016-02-23 & FALSE & Sales & 75689 \\\\\n",
"\t 3240 & Steggall, Shai & Female & 25 & 7 & Master's & 2017-02-23 & FALSE & Operations & 117062 \\\\\n",
"\t 1413 & Tanner, Sean & Male & 25 & 2 & Associate's & 2016-02-23 & FALSE & Operations & 61869 \\\\\n",
"\\end{tabular}\n"
],
"text/markdown": [
"\n",
"| ID | Name | Gender | Age | Rating | Degree | Start_Date | Retired | Division | Salary |\n",
"|---|---|---|---|---|---|---|---|---|---|\n",
"| 7068 | Dimas, Roman | Male | 25 | 8 | High School | 2017-02-23 | FALSE | Operations | 84252 |\n",
"| 7910 | Hopper, Summer | Female | 25 | 7 | Bachelor's | 2017-02-23 | FALSE | Engineering | 100688 |\n",
"| 1230 | Kirgis, Arissa | Female | 25 | 8 | Bachelor's | 2015-02-23 | FALSE | Operations | 113573 |\n",
"| 9249 | Lopez, Karissa | Female | 25 | 8 | Associate's | 2016-02-23 | FALSE | Sales | 75689 |\n",
"| 3240 | Steggall, Shai | Female | 25 | 7 | Master's | 2017-02-23 | FALSE | Operations | 117062 |\n",
"| 1413 | Tanner, Sean | Male | 25 | 2 | Associate's | 2016-02-23 | FALSE | Operations | 61869 |\n",
"\n"
],
"text/plain": [
" ID Name Gender Age Rating Degree Start_Date Retired\n",
"1 7068 Dimas, Roman Male 25 8 High School 2017-02-23 FALSE \n",
"2 7910 Hopper, Summer Female 25 7 Bachelor's 2017-02-23 FALSE \n",
"3 1230 Kirgis, Arissa Female 25 8 Bachelor's 2015-02-23 FALSE \n",
"4 9249 Lopez, Karissa Female 25 8 Associate's 2016-02-23 FALSE \n",
"5 3240 Steggall, Shai Female 25 7 Master's 2017-02-23 FALSE \n",
"6 1413 Tanner, Sean Male 25 2 Associate's 2016-02-23 FALSE \n",
" Division Salary\n",
"1 Operations 84252\n",
"2 Engineering 100688\n",
"3 Operations 113573\n",
"4 Sales 75689\n",
"5 Operations 117062\n",
"6 Operations 61869"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"tail(employeesSortedAgeDescName)"
]
}
],
"metadata": {
"jupytext": {
"cell_metadata_filter": "-all",
"formats": "md:myst",
"text_representation": {
"extension": ".md",
"format_name": "myst",
"format_version": 0.13,
"jupytext_version": "1.11.5"
}
},
"kernelspec": {
"display_name": "R",
"language": "R",
"name": "ir"
},
"language_info": {
"codemirror_mode": "r",
"file_extension": ".r",
"mimetype": "text/x-r-source",
"name": "R",
"pygments_lexer": "r",
"version": "3.6.1"
},
"source_map": [
16,
22,
41,
46,
48,
52,
57,
59,
63,
68
]
},
"nbformat": 4,
"nbformat_minor": 5
}