All data tidying code is contained within the run_analysis.R file.
To run it place the R script in the directory containing the folders of both train and test which contains both the training and test data.
Makes sure that this directory is also the current working directory in R Studios.
Run the script with the command source('run_analysis.R').
You will obtain 2 files final.txt which the tidy data and agg_final.txt which is the aggregated mean of the tidy data over subjects and activity.