This is a script to pre-process a dataset collected from the accelerometers from the Samsung Galaxy S smartphone. A full description can be obtained from here http://archive.ics.uci.edu/ml/datasets/Human+Activity+Recognition+Using+Smartphones.
This script performs the following tasks:
- Load and merge training and testing datasets including subject, activity, and measurement data.
- Extracts only the measurements on the mean and standard deviation for each measurement.
- Apply descriptive activity names to activities in the data set.
- Appropriately labels the data set with descriptive variable names.
- Creates a second, independent tidy data set with the average of each variable for each activity and each subject.
- Export the tide data set to working directory.
The following libraries are required to run this script. If they have not been installed before, use install.packages() to install them before running. Also, be sure to unzip the dataset to working directory before executing the script.
library(reshape2)
library(plyr)Use source("run_analysis.R") to execute the script. Enter the working directory at prompt and hit enter.
The progress indicators will display in the result panel. At the end, the tidy dataset will be saved at the working directory as tidy.txt.
Read training dataset....
Read testing dataset....
Combining datasets....
Read features and extract mean and std....
Assign descriptive names to dataset....
Label data....
Create tidy data....
Export tide data....
Done! Tidy data saved to {working directory}\tidydata.txt.- Produce the intermediate processing datasets for both training and testing data
a. Load subject data
b. Load measurement data
c. Load activity label data - Combine train and test data
a. Subject data
b. Measurement
c. Activity label - Extract measurement on mean and standard deviation
a. Read feature data as table b. Grep measurement name and column id with mean() and std() in the name c. Use column id to get measurements from measurement table and assign column name to measurement table
d. Combine all dataset into one - Assign descriptive activity label to data set
a. Load activity_label data
b. Merge with dataset
c. Remove activity code column - Create tidy data set
a. Melt data set
b. Calculate mean with ddply
c. Dcast data - Export tiday data
The final output is stored in the working directory as tidydata.txt. It contains subject, activity, and features which are mean of mean and standard deviation of the same type of measurement for the same subject and same activity.