The R script is divided into six section as indicated by ## line in the script. The first section "read in data sets" has two sub-sections for reading in training and test data sets accordingly.
##1 train data set ##2 test data set
##task2: Extracts only the measurements on the mean and standard deviation for each measurement. ##task3: Uses descriptive activity names to name the activities in the data set ##task4: Appropriately labels the data set with descriptive activity names. ##task5: Creates a second, independent tidy data set with the average of each variable for each activity and each subject.