Skip to content

johnzeng2010/TidyData

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

One of the most exciting areas in all of data science right now is wearable computing - see for example this article . 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. A full description is available at the site where the data was obtained:

http://archive.ics.uci.edu/ml/datasets/Human+Activity+Recognition+Using+Smartphones

Here are the data for this project:

https://d396qusza40orc.cloudfront.net/getdata%2Fprojectfiles%2FUCI%20HAR%20Dataset.zip

All data files' descriptions are listed in the "README.txt" inside above zip file.

This project is to create "run_analysis.R" R script to implement following 5 requirements:

  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.

The generated tidy data is uploaded to "https://s3.amazonaws.com/coursera-uploads/user-50f468110614a37410638391/973500/asst-3/3a4c6ae0ea9911e4b252693ad2083e29.txt". You can download and load it to your R or RStudio through following R command:

tidy <- read.table("tidy.txt", header=TRUE)

For your convenience, you can view such data file by doing following:

address <- "https://s3.amazonaws.com/coursera-uploads/user-50f468110614a37410638391/973500/asst-3/3a4c6ae0ea9911e4b252693ad2083e29.txt"
address <- sub("^https", "http", address)
data <- read.table(url(address), header = TRUE) 
View(data)

The format of such tidy data is documented in "CodeBook.txt" file.

Following is the details of how such 5 requirements are implemented in "run_analysis.R":

  1. Data files are loaded into R through "read.table"
  2. Put column name to each data frame. Feature names and activity labels are directly from "features.txt" and "activity_labels.txt" file.
  3. Merge X_train, y_train and subject_train by "cbind". Do similar thing for test data sets.
  4. Merger train and test data by "rbind"
  5. Extract only the measurements related to "mean" and "standard deviation" by matching feature names with "-mean()" and "-std()". By changing the matching regex (for example, adding matching for "meanFreq"), we can fetch different features. But for this project, this should be good enough.
  6. Once the data sets are related to only these required measurements(features), activities are labelled using the descriptive activity names.
  7. Then, tidy data set is generated by "melting" and "aggregating" through "activity" and "subject". The long format is used to contain following 4 columns in final tidy data set:
  • "activity_labels"
  • "subject"
  • "feature"
  • "mean"

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages