Module # 8 Input/Output, string manipulation and plyr package
This week was all about manipulating a file and outputting a new one.
Starting with I imported Plyr, this will be used to manipulate the data.
library(plyr)
I then imported the file that was given to us and did the first use of dply with ddply.
Student_assignment_6 <- read.csv("Assignment 6 Dataset.txt", header = TRUE)
StudentAverage <- ddply(Student_assignment_6, "Sex", transform,
Grade.Average = mean(Grade))
print(StudentAverage)
I know that dpplyr should have a way to do this next step but I struggled with it a bit and just split it for my own sake.
mean_male <- mean(Student_assignment_6$Grade[Student_assignment_6$Sex == "Male"])
mean_female <- mean(Student_assignment_6$Grade[Student_assignment_6$Sex == "Female"])
I then used Grep command to make a subset of people with I in their name. In order to get both upper and lower I used [iI] so it read both
i_students <- subset(Student_assignment_6, grepl("[iI]", Name))
Comments
Post a Comment