-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_analysis.R
More file actions
43 lines (30 loc) · 1.68 KB
/
run_analysis.R
File metadata and controls
43 lines (30 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
## Test section part
testParticipants <- read.table("test/subject_test.txt")
testCategories <- read.table("test/y_test.txt")
testRawData <- read.table("test/X_test.txt")
colnames(testParticipants) <- "Participant"
colnames(testCategories) <- "Category"
fusedTest <- cbind(testParticipants,testCategories,testRawData)
###############################################################
##Train section part
trainParticipants <- read.table("train/subject_train.txt")
trainCategories <- read.table("train/y_train.txt")
trainRawData <- read.table("train/X_train.txt")
colnames(trainParticipants) <- "Participant"
colnames(trainCategories) <- "Category"
fusedTrain <- cbind(trainParticipants,trainCategories,trainRawData)
##################################################################
allFused <- rbind(fusedTest, fusedTrain)
##Feautres part
tableFeatures <- read.table("features.txt",stringsAsFactors=F,strip.white=T)
##selecting just the standard deviation and the mean.
selectedFeatures <- tableFeatures[grep("std()|mean\\()",tableFeatures$V2),]
##get activity labels
activityLabels <- read.table("activity_labels.txt",stringsAsFactors=F)
##skip the participants and the category
allFusedWithLabels <- allFused[,c(1,2,selectedFeatures$V1+2)]
allFusedWithLabels$Category <- activityLabels[allFusedWithLabels$Category,2]
##making observations about participants in each different category.
tidyDataSet <- aggregate(allFusedWithLabels[,3:ncol(allFusedWithLabels)],by=list(participant = allFusedWithLabels$Participant,
category = allFusedWithLabels$Category),mean)
write.table(file = "tidyDataSet.txt" row.name=FALSE, x = tidyDataSet)