Here is a link to the data set home page: Human Activity Recognition Using Smartphones Data Set
If for some reason my tidy data set does not appear on the Coursera webpage of Reproducible Research, please find it in the GitHub repository: https://github.com/ibanmd/RepResearchAssgn2 It is called "tidydata.txt"
I have written most of this assignment in an informal tone, because I know that my audience also worked on the same material and is familiar with it.
Note In order to make this script work on a Windows computer (it was made to work on a Mac), replace lines 6, 7 and 8 of my script with these 3 lines:
dataURL <- "http://d396qusza40orc.cloudfront.net/getdata%2Fprojectfiles%2FUCI%20HAR%20Dataset.zip"
destFile <- paste(workingDir,"/RepResearchAssignment2.zip", sep="")
download.file(url=dataURL, destfile=destFile)
Basically, in order to work on a Windows computer, the "https" is changed to "http" and the method="curl" is removed.
The script reads in the various data sets found in the folder "UCI HAR Dataset", pieces them together into one big data frame, and then finds the mean for each column and for each unique combination of Subject ID and Activity ID. After it does this, it creates a text file called "tidydata.txt" inside that same folder.
All that is required for the script to work is to simply run it! See note below Here is a quick summary of what the my version of run_analysis.R does:
- Downloads the .zip file from Coursera into your working directory. I am not certain that this will work on any computer, but it should work on any Mac.
- Unzips the file, creating the "UCI HAR Dataset"" folder.
- Loads all the various data sets into R and combines them into 1 data frame, of dimension 563x10299
- Adds in the column names to the data frame
- Uses grep() to subset the data frame to include columns with "mean()" or "std()"
- Uses gsub() to clean up the column names
- Replaces the numbers 1 through 6 in the Activity ID column with their corresponding names
- Uses aggregate() to take the mean of each column by each combination of Subject and Activity
- Creates a text file of the resulting 180x68 data frame and puts it into the "UCI HAR Dataset" folder