You should 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.
These are the high level steps involved in completing the requirements outlined above. For additional details, please refer to the code.
- Concatenate the test and training sets (rbind).
- Extract only those features (columns/variables) we are interested in (means and standard deviations).
- Add columns for the activity code and subject code (cbind, rbind).
- Convert the activity code to a human readable label (factor).
- Update the column headers.
- Write the data to a file.
- Looping over the number of subject and the activities:
- Extract the subset of data for each subject-activity pair.
- Calculate the column means and add the results to a data data frame.
- Add the subject and activity columns.
- Add the column headers.
- Write to a file.
Only those features whose feature names end in "mean()" or "std()" we included in the analysis. There are other features which also represent variations on mean or standard deviation calculations, but these were left out for this exercise. If these features are of interest, it is sufficient to add their column position to the "features" vector in run_analysis.R.
Column headers were added to the data set to make clear what the measurements in each column represent. The column headers were taken directly from the features.txt file. More descriptive names may have been appropriate but would require some degree of interpretation. I have adopted the position that such interpretation should be left to a domain expert. The labels from the features.txt file will be meaningful to any domain expert familiar with the data set.
Both tidy data sets are CSV files with a row of column headers. The data sets can be read into R as follows:
my.data <- read.csv("/path/to/file", header=TRUE)