This repository contains the course project for the Coursera course Getting and Cleaning data course, part of the Data Science Specialization.
The purpose of this project is to demonstrate the ability to collect, work with, and clean a data set. The goal is to prepare a tidy data set that can be used for later analysis.
The project requires the following output:
-
A tidy data set as described below
-
This Github repository with the run_analysis.R script for performing the analysis
-
A code book that describes the variables, the data, and any transformations or work that you performed to clean up the data called CodeBook.md.
One of the most exciting areas in all of data science right now is wearable computing - see for example this article: http://tinyurl.com/dsatatbftwtsb. Companies like Fitbit, Nike, and Jawbone Up are racing to develop the most advanced algorithms to attract new users. The data linked to from the course website represent data collected from the accelerometers from the Samsung Galaxy S smartphone.
The source data for this project was obtained here:
https://d396qusza40orc.cloudfront.net/getdata%2Fprojectfiles%2FUCI%20HAR%20Dataset.zip
A full description of the data is available at the site where the data was obtained: http://archive.ics.uci.edu/ml/datasets/Human+Activity+Recognition+Using+Smartphones
The goal of the project is to output a tidy data set containing only the average of the mean and the standard deviations of each activity and each subject from both the train and test data included in the zip file referenced above.
The run_analysis.R script can by sourcing the file from within R Studio.
The script will attempt to read data, download data if needed, and output results to the current working directory so it is recommended that you set it accordingly with setwd() prior to running it. If you already have a copy of the data on your local system, set the working directory to the parent folder of that data, or its zip file.
The run_analysis.R script does the following:
-
If the folder "UCI HAR Dataset" is not present in your current working directory, it will do the following:
- Check to see if the zip file is present
- If the zip file is not present, it is downloaded to the current working directory.
- Uzip the zip file.
-
Extracts only the measurements on the mean and standard deviation for each measurement from both the test and train sets.
-
Uses descriptive activity names to name the activities in the data set
-
Appropriately labels the data set with descriptive variable names.
-
From the data set in step 4, creates a second, independent tidy dataset with the average of each variable for each activity and each subject.
The output file, tidy.txt, can be read back into R Studio with:
data <- read.table("tidy.txt", header = TRUE)
View(data)
Sample output:
Loading required package: data.table
Loading required package: reshape2
Did not find 'UCI HAR Dataset' directory
Downloading 'UCI HAR Dataset.zip' from https://d396qusza40orc.cloudfront.net/getdata%2Fprojectfiles%2FUCI%20HAR%20Dataset.zip...
Unzipping file...
Processing test data...
Processing train data...
Pivoting data...
Creating tidy data set...
Writing tidy data set to 'tidy.txt'...
See CodeBook.md for more detail on the output.