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))

lastly i wrote it to a table with this final command 

write.table(i_students, "i_students", sep = ",")


In all this showed several ways to interact with datasets and fine tune exactly what you want to use. 

Comments

Popular posts from this blog

Assignment #10: Building Your Own R Package

Module # 7 R Object: S3 vs. S4 assignment

Week 3