-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript3.R
More file actions
70 lines (56 loc) · 2.42 KB
/
Copy pathscript3.R
File metadata and controls
70 lines (56 loc) · 2.42 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#
# script3.R
#
# Performs step 3 in the Code Book.
#
# Label all the rows and columns of every table, in a such a way that
# we can later merge them as needed. Add, move, and renamem columns as
# required.
#
# STEP A - put the feature and activity names and IDs into the feature
# and activity tables
features <- rename(features, "feature_id"=V1, "feature_name"=V2)
activity_labels <- rename(activity_labels, "activity_id"=V1, "activity_name"=V2)
# STEP B - put the experiment group into the X table (which contains
# the processed/calculated observations for each experiment)
X_train$group <- "Train"
X_test$group <- "Test"
# STEP C - combine the training and testing tables
body_acc_x <- rbind(body_acc_x_train, body_acc_x_test)
body_acc_y <- rbind(body_acc_y_train, body_acc_y_test)
body_acc_z <- rbind(body_acc_z_train, body_acc_z_test)
body_gyro_x <- rbind(body_gyro_x_train, body_gyro_x_test)
body_gyro_y <- rbind(body_gyro_y_train, body_gyro_y_test)
body_gyro_z <- rbind(body_gyro_z_train, body_gyro_z_test)
total_acc_x <- rbind(total_acc_x_train, total_acc_x_test)
total_acc_y <- rbind(total_acc_y_train, total_acc_y_test)
total_acc_z <- rbind(total_acc_z_train, total_acc_z_test)
subject <- rbind(subject_train, subject_test)
X <- rbind(X_train, X_test)
y <- rbind(y_train, y_test)
# STEP D - add an experiment_id column to each table
# so we can easily merge tables
experiment <- data.frame("experiment_id"=seq(1:10299))
body_acc_x <- cbind(body_acc_x, experiment)
body_acc_y <- cbind(body_acc_y, experiment)
body_acc_z <- cbind(body_acc_z, experiment)
body_gyro_x <- cbind(body_gyro_x, experiment)
body_gyro_y <- cbind(body_gyro_y, experiment)
body_gyro_z <- cbind(body_gyro_z, experiment)
total_acc_x <- cbind(total_acc_x, experiment)
total_acc_y <- cbind(total_acc_y, experiment)
total_acc_z <- cbind(total_acc_z, experiment)
subject <- cbind(subject, experiment)
X <- cbind(X, experiment)
y <- cbind(y, experiment)
# STEP E - rename the subject ID and activity ID
# columns in the subject and activity tables
subject <- rename(subject, "subject_id"=V1)
y <- rename(y, "activity_id"=V1)
# STEP F - construct a vector of feature names
# (plus the group and experiment IDs) and apply
# it to the X table (which contains the processed
# observations)
feature_names <- features$feature_name
feature_names <- c(feature_names, c("group", "experiment_id"))
names(X) <- feature_names