-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_analysis.R
20 lines (20 loc) · 1.14 KB
/
run_analysis.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
X_train <- read.table('./UCI HAR Dataset/train/X_train.txt')
y_train <- read.table('./UCI HAR Dataset/train/y_train.txt')
X_test <- read.table('./UCI HAR Dataset/test/X_test.txt')
y_test <- read.table('./UCI HAR Dataset/test/y_test.txt')
subject_train <- read.table('./UCI HAR Dataset/train/subject_train.txt')
subject_test <- read.table('./UCI HAR Dataset/test/subject_test.txt')
feature_name <- read.table('./UCI HAR Dataset/features.txt')
activity_name <- read.table('./UCI HAR Dataset/activity_labels.txt')
Xy_train <- cbind(X_train, y_train, subject_train)
Xy_test <- cbind(X_test, y_test, subject_test)
mergeDF <- rbind(Xy_train, Xy_test)
feature_name <- as.character(feature_name$V2)
sub_mean_std <- grep('mean\\(\\)|std\\(\\)', feature_name)
mergeDF1 <- mergeDF[,c(sub_mean_std, ncol(mergeDF)-1, ncol(mergeDF))]
names(mergeDF1) <- c(feature_name[sub_mean_std], 'activity', 'subject')
library("dplyr")
mergeDF1 <- mutate(mergeDF1, activity = activity_name$V2[activity])
activitysubject <- group_by(mergeDF1, activity, subject)
tidy_data <- summarise_each(activitysubject, funs(mean))
write.table(tidy_data, './UCI HAR Dataset/tidy.data.txt', row.names = F)