from https://d396qusza40orc.cloudfront.net/getdata%2Fprojectfiles%2FUCI%20HAR%20Dataset.zip create one R script called run_analysis.R that does the following:
- Merges the training and the test sets to create one data set.
- Extracts only the measurements on the mean and standard deviation for each measurement.
- Uses descriptive activity names to name the 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.
- Read X_train.txt, y_train.txt, subject_train.txt from "./data/train" and safe in "trainX", "trainY" and "trainSubject" respectively.
- Read X_test.txt, y_test.txt, subject_test.txt from "./data/test" and safe in "testData", "testLabel" and "testsubject" respectively.
- Concatenate testData and trainData to generate a 10299x561 data frame "Data"; do the same with testLabel and trainLabel to generate a 10299x1 data frame "Label"; join testSubject to trainSubject to generate a 10299x1 data frame "Subject".
- Read features.txt from "/data" and safe in "features". Extract the measurements on the mean and standard deviation. Finaly we obtain a 66 indices list. We get a subset of Data with 66 columns.
- Clean the column names of the subset. We remove the "()" and "-" symbols in the names, as well as make the first letter of "mean" and "std" a capital letter "M" and "S" respectively.
- Read activity_labels.txt from "./data"" and in "activity".
- Clean the activity names in the second column of activity. We first make all names to lower cases. If the name has an underscore between letters, we remove the underscore and capitalize the letter immediately after the underscore.
- Transform the values of Label according to the activity data frame.
- Combine the Subject, Label and Data by column to get a new cleaned 10299x68 data frame "rawData". Properly name the first two columns, "Subject" and "Activity". The Subject column contains integers that range from 1 to 30 inclusive; the Activity column contains 6 kinds of activity names; the last 66 columns contain measurements that range from -1 to 1 exclusive.
- Write the rawData out to "rawdata.txt" file in current working directory.
- Generate a second independent tidy data set with the average of each measurement for each activity and each subject. We have 30 unique subjects and 6 unique activities, which result in a 180 combinations of the two. For each combination, we calculate the mean of each measurement with the corresponding combination. So, after initializing the result data frame and performing the two for-loops, we get a 180x68 data frame. Write the result out to "tidydata.txt" file in current working directory.