TRM Practical Data Analysis – Basic level

Lecture 1. Introduction to R and R Markdown

Task 2: Install the following packages

install.packages (c(“readxl”, “tidyverse”, “table1”, “compareGroups”, “ggplot2”, “grid”, “gridExtra”, “GGally”, “ggthemes”, “DescTools”, “simpleboot”, “lmboot”), dependencies=T)

Task 3: Import the csv data set “Professorial Salaries” into R

salary = read.csv("C:\\Users\\24549750\\OneDrive - UTS\\PhD\\PhD第二学期\\module 10\\Professorial Salaries.csv")

Task 4: Describe the salary data set

4.1 How many participants/variables are there in the “salary” data set?

dim(salary)
## [1] 397   9

4.2 List the variable names

names(salary)
## [1] "ID"            "Rank"          "Discipline"    "Yrs.since.phd"
## [5] "Yrs.service"   "Sex"           "NPubs"         "Ncits"        
## [9] "Salary"

4.3 List the first 6 observations

head(salary)
##   ID      Rank Discipline Yrs.since.phd Yrs.service  Sex NPubs Ncits Salary
## 1  1      Prof          B            19          18 Male    18    50 139750
## 2  2      Prof          B            20          16 Male     3    26 173200
## 3  3  AsstProf          B             4           3 Male     2    50  79750
## 4  4      Prof          B            45          39 Male    17    34 115000
## 5  5      Prof          B            40          41 Male    11    41 141500
## 6  6 AssocProf          B             6           6 Male     6    37  97000

Task 5: Create a new variable “salary.level”

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.0     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
salary=salary %>% mutate(salary.level= case_when(Salary>=130000~ "High", Salary>=100000 & Salary<130000~"Medium", Salary<100000~"Low"))

Task 6: Create a new variable “high.salary”

salary=salary %>% mutate(high.salary= case_when(Salary>130000~ "1", Salary<130000~"0"))

Task 7: Create a new variable “salary.aud” as professor’s salaries in AUD (USD/AUD ratio = 1.53)

salary=salary %>% mutate(salary.aud= Salary*1.53)

Task 8: Select a subset of participants that includes male professors in the theoretical department who had high salaries

Men.A.High=salary %>% filter(Sex=="Male", Discipline=="A", salary.level=="High")
dim(Men.A.High)
## [1] 40 12

Task 9: Create a new data set that includes 4 variables (ID, Rank, Sex and Salary)

ID.Rank.Sex.Salary=salary %>% select(ID,Rank,Sex,Salary)

Task 10: Save all your work and publish it into your Rpubs account