The script expects the data to be in a folder called "UCI HAR Dataset" in the current working directory. It reads first test data and then rbinds the train data. So all datasets have the test data before the training data and the rows correspond.
It reads the test and train X data with the descriptive variable names specified in "features.txt", then it keeps the variables that have the string "mean..." or "std..." in the name and discards all the others.
Next, it adds the activities, reading the activity codes from test and train data and joining it with the names defined in "activity_labels.txt". The subject is also read and added as a column.
Finally, the table is melted and dcasted in order to have the mean by each group. The groups are defined by a new variable resulting from concatenating the subject and the activity.
The resulting dataset has these variables. The subjectActivity variable represents the combination of subject and activity, the rest of the variables are the mean for the original ones:
[1] "subjectActivity"
[2] "tBodyAcc.mean...X"
[3] "tBodyAcc.mean...Y"
[4] "tBodyAcc.mean...Z"
[5] "tBodyAcc.std...X"
[6] "tBodyAcc.std...Y"
[7] "tBodyAcc.std...Z"
[8] "tGravityAcc.mean...X"
[9] "tGravityAcc.mean...Y"
[10] "tGravityAcc.mean...Z"
[11] "tGravityAcc.std...X"
[12] "tGravityAcc.std...Y"
[13] "tGravityAcc.std...Z"
[14] "tBodyAccJerk.mean...X"
[15] "tBodyAccJerk.mean...Y"
[16] "tBodyAccJerk.mean...Z"
[17] "tBodyAccJerk.std...X"
[18] "tBodyAccJerk.std...Y"
[19] "tBodyAccJerk.std...Z"
[20] "tBodyGyro.mean...X"
[21] "tBodyGyro.mean...Y"
[22] "tBodyGyro.mean...Z"
[23] "tBodyGyro.std...X"
[24] "tBodyGyro.std...Y"
[25] "tBodyGyro.std...Z"
[26] "tBodyGyroJerk.mean...X"
[27] "tBodyGyroJerk.mean...Y"
[28] "tBodyGyroJerk.mean...Z"
[29] "tBodyGyroJerk.std...X"
[30] "tBodyGyroJerk.std...Y"
[31] "tBodyGyroJerk.std...Z"
[32] "fBodyAcc.mean...X"
[33] "fBodyAcc.mean...Y"
[34] "fBodyAcc.mean...Z"
[35] "fBodyAcc.std...X"
[36] "fBodyAcc.std...Y"
[37] "fBodyAcc.std...Z"
[38] "fBodyAccJerk.mean...X"
[39] "fBodyAccJerk.mean...Y"
[40] "fBodyAccJerk.mean...Z"
[41] "fBodyAccJerk.std...X"
[42] "fBodyAccJerk.std...Y"
[43] "fBodyAccJerk.std...Z"
[44] "fBodyGyro.mean...X"
[45] "fBodyGyro.mean...Y"
[46] "fBodyGyro.mean...Z"
[47] "fBodyGyro.std...X"
[48] "fBodyGyro.std...Y"
[49] "fBodyGyro.std...Z"