data <- "https://vincentarelbundock.github.io/Rdatasets/csv/AER/BankWages.csv"
bwages <- read.csv(file = data , header = TRUE , sep = ",")
head(bwages)
## X job education gender minority
## 1 1 manage 15 male no
## 2 2 admin 16 male no
## 3 3 admin 12 female no
## 4 4 admin 8 female no
## 5 5 admin 15 male no
## 6 6 admin 15 male no
Question 2 Create a new dataframe with a subset of the columns and
rows. Make sure to rename it
bwages2 <- subset(bwages[c(10:20),c(1,3)])
head(bwages2)
## X education
## 10 10 12
## 11 11 16
## 12 12 8
## 13 13 15
## 14 14 15
## 15 15 12
Question 3 Create new column names for the new data frame
colnames(bwages2) <- c('Col1', 'Col2')
print(bwages2)
## Col1 Col2
## 10 10 12
## 11 11 16
## 12 12 8
## 13 13 15
## 14 14 15
## 15 15 12
## 16 16 12
## 17 17 15
## 18 18 16
## 19 19 12
## 20 20 12
Question 5 For atleast 3 values in a column please rename so that
every value is renamed.
bwages2$Col1 <- paste("ID", bwages2$Col1, sep = "-")
bwages2
## Col1 Col2
## 10 ID-10 12
## 11 ID-11 16
## 12 ID-12 8
## 13 ID-13 15
## 14 ID-14 15
## 15 ID-15 12
## 16 ID-16 12
## 17 ID-17 15
## 18 ID-18 16
## 19 ID-19 12
## 20 ID-20 12
Question 6 Display enough rows to see examples of all of steps 1-5
above.
head(bwages2)
## Col1 Col2
## 10 ID-10 12
## 11 ID-11 16
## 12 ID-12 8
## 13 ID-13 15
## 14 ID-14 15
## 15 ID-15 12
Question 7 BONUS – place the original .csv in a github file and have
R read from the link.
data <- "https://vincentarelbundock.github.io/Rdatasets/csv/AER/BankWages.csv"
bwages <- read.csv(file = data , header = TRUE , sep = ",")
head(bwages)