Module 8: Input/Output, String Manipulation and 'plyr' Package

Module 8: Input/Output, String Manipulation and 'plyr' Package

In this weeks assignment, we used a variety of functions to import, define, modify and resave a dataset provided to us by using various functions to produce a filtered list of names and values to where that all members were organized by sex and by average grade, and then were filtered down using the grepl(), to students of both sexes that have an I or i in their name. Maintaining the same syntactical arguements, a resulting table entitled "DataSubset" was created and saved. I compiled into a .docx and will submit in canvas but here is the R script from RStudio:

##Module # 8 Input/Output, String Manipulation and plyr package.

#This weeks assignment deals with a short process of importing, changing, cleaning and resaving data within R from a non-native filetype

##Add your libraries first

##Then, we must first import the data from what was provided to us in the instructions


library(dplyr)

library(plyr)

library(tidyverse)


##Step 1: Import the data into the R environment


x <- read.table(file.choose(new = FALSE), header = TRUE, sep = ",")


##Step 2: Use plyr call ddply() and generate the mean for Age and Grade, filtered by gender


ddply(x,"Sex",transform,Grade.average=mean(Grade))


#Step 3: Print this new table to a file


write.table(x,"Sorted Average",sep = ",")


#Step 4: Filter the names that contain the letter 'i'

##I in this case is both the capital and lower case letter

##HINT: use [iI] in grepl()


xvar = subset(x,grepl("[iI]",x$Name))

xvar


#Step 5: Write this final subset to a file


write.table(xvar,"DataSubset",sep = ",")



Comments

Popular posts from this blog

R Package: pfStat

Module 7 Assignment

The Tampa Feasibility Report featuring R based Visualizations