scumdogsteev / getting-and-cleaning-data

Getting and Cleaning Data Course Project

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting and Cleaning Data Course Project

by Steve Myles, February 2015

Assignment:

You should create one R script called run_analysis.R that does the following.

  1. Merges the training and the test sets to create one data set.
  2. Extracts only the measurements on the mean and standard deviation for each measurement.
  3. Uses descriptive activity names to name the activities in the data set
  4. Appropriately labels the data set with descriptive variable names.
  5. From the data set in step 4, creates a second, independent tidy data set with the average of each variable for each activity and each subject.

Files:

  1. README.md (this file)
  2. run_analysis.R (the R script that does the merging and transformations)
  3. CodeBook.md (describes the variables, the data, the transformations, and the work that is performed to clean up the data)

Assumptions

  1. The Samsung data is available in the working directory and/or the user is connected to the Internet. The script checks:
  2. If an unzipped folder named "UCI HAR Dataset" with the directory structure underneath that left intact from the original zip file (e.g., there are subdirectories called "test" and "train" in "UCI HAR Dataset") is available. If so, the script continues.
  3. If the "UCI HAR Dataset" folder is not available, the script checks whether the original zip file is available. If so, it is unzipped and the script continues.
  4. If the original zip file is not available, the script downloads the file from the Internet, unzips it, and continues the script.
  5. The user has either previously installed the plyr, dplyr, and reshape2 packages or is connected to the Internet so the script can install them.
  6. "Extracts only the measurements on the mean and standard deviation" is assumed to mean all variables from the original data set with the strings "Mean," "mean," or "std" in their names.

Process

run_analysis.R goes through the following process to meet the requirements. Please see the script for details about how each step is performed.

  1. Check whether the UCI HAR Dataset is available in the working directory. If not, the script checks for the zip file, unzips it, and continues. If that is also unavailable, the script downloads the zip file, unzips it, and continues.
  2. Merge the training and the test sets to create one data set (requirement #1)
  3. Load the "plyr," "dplyr," and "reshape2" packages as they are necessary for the data manipulation that follows. If they have not been previously installed, the script installs them.
  4. Read the "Activity Labels" and "Features" data into data frames, labeling the columns and changing the Feature data to character type.
  5. Read the separate parts of the training data set (training activities, "y_train.txt;" training data, "X_train.txt;" and training subject, "subject_train.txt") and combine them into a single data frame using cbind.
  6. Read the separate parts of the test data set (test activities, "y_test.txt;" test data, "X_test.txt;" and test subject, "subject_test.txt") and combine them into a single data frame using cbind.
  7. Merge the training and test data sets into a single data frame using rbind.
  8. Add activity labels from the "Activity Labels" data frame (Uses descriptive activity names to name the activities in the data set (requirement #3))
  9. Name the columns based on the "Features" data (Appropriately labels the data set with descriptive variable names (requirement #4))
  10. Extract only the measurements on the mean and standard deviation for each measurement (requirement #2)
  11. Subset the merged data frame to the columns representing mean and standard deviation
  12. To do this, search for all variable names containing the strings "Mean," "mean," and "std."
  13. Create a second, independent tidy data set with the average of each variable for each activity and each subject (requirement #5)
  14. Make all column names legal for R by removing all parentheses and dashes.
  15. Change variable names to Camel Case (i.e., capitalize "Mean" and "Std" regardless of where in the column name they appear) to increase readability.
  16. Change the names of the misnamed variables in the original data set (i.e., change "BodyBody" to "Body").
  17. Change the "Subject" column to a factor for easier manipulation.
  18. Sort the merged data frame by "Subject" and "Activity"
  19. Calculate the average (mean) of each numeric column and return a data frame ("merged_summary" in the script) with the average for each subject/activity combination.
  20. As instructed, write this data frame to a text file called "samsung_summary.txt" using "row.names = FALSE."

References

  1. Sean C. Anderson. An Introduction to reshape2. Blog post on http://seananderson.ca/. Oct 2013.
  2. Davide Anguita, Alessandro Ghio, Luca Oneto, Xavier Parra and Jorge L. Reyes-Ortiz. Human Activity Recognition on Smartphones using a Multiclass Hardware-Friendly Support Vector Machine. International Workshop of Ambient Assisted Living (IWAAL 2012). Vitoria-Gasteiz, Spain. Dec 2012.
  3. "GitHub Flavored Markdown." GitHub Help. 2015.
  4. Simon Hanlon. Response to "Elegant way to check for missing packages and install them?". Stack Overflow. Nov 2013.
  5. David Hood. David's Course Project FAQ. Getting and Cleaning Data Discussion Forum. Coursera. Feb 2015.
  6. David Hood. Response to "Final Step". Getting and Cleaning Data Discussion Forum. Coursera. Feb 2015.
  7. David Hood. Response to "Codebook". Getting and Cleaning Data Discussion Forum. Coursera. Feb 2015.
  8. Kenneth Karan. Response to "Any standard format for codebook?". Getting and Cleaning Data Discussion Forum. Coursera. Feb 2015.
  9. Matthew Taylor. Response to "Silly situation: trouble with unzipping the DataSet.zip file". Response on Getting and Cleaning Data Discussion Forum. Coursera. Feb 2015.

About

Getting and Cleaning Data Course Project


Languages

Language:R 100.0%