R Programming Journal Module 8 - Wesley Huang
- Wesley Huang
- Mar 8
- 1 min read
In this assignment, I imported a student dataset into R and used the plyr package to calculate the mean grade using Sex as the category. First, I used the read.table() function to import the dataset into R. The dataset contained student names, ages, sex, and grades. After importing the data, I verified that the dataset loaded correctly by printing it in the console.

Next, I used the ddply() function from the plyr package to group the dataset by Sex and calculate the average grade for each category. This created a new variable called Grade.Average that showed the mean grade for male and female students. The results showed that female students had an average grade of 86.9375, while male students had an average grade of 80.25.

After calculating the averages, I filtered the dataset to find students whose names contained the letter “i”. To do this, I used the subset() function together with grepl("[iI]", students$Name) so that both lowercase and uppercase versions of the letter would be included. This created a new dataset containing only the students whose names contained the letter “i”.

Finally, I exported both results to files. The dataset containing the average grades by sex was written to a CSV file called Students_Gendered_Mean.csv. The filtered dataset containing names with the letter “i” was also exported to a CSV file called I_Students.csv. This assignment helped me practice importing data, grouping data by category, filtering rows using text patterns, and exporting results from R.



Comments