Module # 8 Input/Output, string manipulation and plyr package

#Step 1
col_names= c('Name','Age','Sex','Grade')
Student_assignment6 <- read.table('Assignment 6 Dataset.txt', sep=',', header=TRUE, col.names = col_names)
Student_assignment6

##         Name Age    Sex Grade
## 1     Booker  18   Male    83
## 2      Lauri  21 Female    90
## 3     Leonie  21 Female    91
## 4    Sherlyn  22 Female    85
## 5    Mikaela  20 Female    69
## 6    Raphael  23   Male    91
## 7       Aiko  24 Female    97
## 8   Tiffaney  21 Female    78
## 9     Corina  23 Female    81
## 10 Petronila  23 Female    98
## 11    Alecia  20 Female    87
## 12   Shemika  23 Female    97
## 13    Fallon  22 Female    90
## 14   Deloris  21 Female    67
## 15    Randee  23 Female    91
## 16     Eboni  20 Female    84
## 17   Delfina  19 Female    93
## 18 Ernestina  19 Female    93
## 19      Milo  19   Male    67
#Step 2
install.packages("plyr")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.2'
## (as 'lib' is unspecified)
library(plyr) 
Student <- ddply(Student_assignment6,"Sex",transform, Grade.Average=mean(Grade))
Student
##         Name Age    Sex Grade Grade.Average
## 1      Lauri  21 Female    90      86.93750
## 2     Leonie  21 Female    91      86.93750
## 3    Sherlyn  22 Female    85      86.93750
## 4    Mikaela  20 Female    69      86.93750
## 5       Aiko  24 Female    97      86.93750
## 6   Tiffaney  21 Female    78      86.93750
## 7     Corina  23 Female    81      86.93750
## 8  Petronila  23 Female    98      86.93750
## 9     Alecia  20 Female    87      86.93750
## 10   Shemika  23 Female    97      86.93750
## 11    Fallon  22 Female    90      86.93750
## 12   Deloris  21 Female    67      86.93750
## 13    Randee  23 Female    91      86.93750
## 14     Eboni  20 Female    84      86.93750
## 15   Delfina  19 Female    93      86.93750
## 16 Ernestina  19 Female    93      86.93750
## 17    Booker  18   Male    83      80.33333
## 18   Raphael  23   Male    91      80.33333
## 19      Milo  19   Male    67      80.33333
#Step 3
write.table(Student,"Sorted_Average",sep=",") 

#Step 4
Student_filter <- subset(Student_assignment6,grepl("[iI]",Student_assignment6$Name))
write.table(Student_filter,"DataSubset",sep=",") 

Comments