##README This file is used to describe how run_analysis.R works. run_analysis.R can be run as long as the Samsung data is in the working directory
##Script Description ###Load packages
library("dplyr") library("reshape2")
data set, steps 1.1-1.5 are for this purpose
X_test <- read.table("X_test.txt") subject_test <- read.table("subject_test.txt") y_test <- read.table("y_test.txt") X_train <- read.table("X_train.txt") subject_train <- read.table("subject_train.txt") y_train <- read.table("y_train.txt") features <- read.table("features.txt")
names(X_test) <- features$V2 names(X_train) <- features$V2 names(subject_test) <- "subject" names(subject_train) <- "subject" names(y_test) <- "activity" names(y_train) <- "activity"
test <- cbind(subject_test, y_test, X_test)
train <- cbind(subject_train, y_train, X_train)
test_train <- rbind(test,train)
for each measurement
test_train_ms <- test_train[,c(1,2,grep("mean|std", colnames(test_train)))]
in the data set
test_train_ms$activity <- gsub("1","WALKING", test_train_ms$activity) test_train_ms$activity <- gsub("2","WALKING_UPSTAIRS", test_train_ms$activity) test_train_ms$activity <- gsub("3","WALKING_DOWNSTAIRS", test_train_ms$activity) test_train_ms$activity <- gsub("4","SITTING", test_train_ms$activity) test_train_ms$activity <- gsub("5","STANDING", test_train_ms$activity) test_train_ms$activity <- gsub("6","LAYING", test_train_ms$activity)
variable names, which I alreday did at step 1.2
tidy data set with the average of each variable for each activity and each subject.
test_train_group <- group_by(test_train_ms, activity, subject) test_train_mean <- summarise_each(test_train_group, funs(mean))
write.table(test_train_mean, file="test_train_mean.txt",row.names=FALSE)