Assignment #8: Input/Output, String Manipulation, and the plyr Package

 



student <- read.csv(file.choose(), stringsAsFactors = FALSE), reads the file and saves it as a data frame which I named it student. This lets R load in the dataset so we can work with it.

library(ply) uses the plyr package, which includes functions for grouping and summarizing data. I need plyr to calculate the avg grade for each gender gorup.

gender_mean <- ddply(student, .(Sex), summarise, GradeAverage = mean(Grade, na.rm = TRUE)), takes the student data and groups it with "Sex" and calculates the average of the grade for each group and saves it to gender_mean.

The next line saves the the result to a file names gender_mean.txt

i_students <- subset(student, grepl("i", Name, ignore.case = TRUE)), looks at all the names and takes in names that have "i" in it and group it to a new dataset called i_students.

write.csv(i_students, "i_students_full.csv", row.names = FALSE), saves the data we made earlier with students that have the letter i and the code will create the folder with the name of the new file.





Comments

Popular posts from this blog

Assignment #5: Matrix Algebra in R

Assignment #11: Debugging and Defensive Programming in R