-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rhistory
216 lines (216 loc) · 8.29 KB
/
.Rhistory
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
testPath= "C:/Users/recve/ViewPoint_Transformation_Task/78977_Test_0908.csv"
## load up the packages
## use install.packages() to install new packages
library(plyr)
library(dplyr)
library(tidyverse)
library(reshape2)
## ---------------------------
#####----------Load Experiment Data----------#####
## read csv files
csv_files_ls <- list.files(
path=thePath,
pattern = "*.csv")
csv_files_df <- lapply(csv_files_ls,
function(x)
{
tmp <- try(read.csv(
file = x,
header = TRUE))
if (!inherits(tmp,
'try-error'))
tmp
}
)
## combine all csv files together
combined_df <- do.call("rbind",
lapply(csv_files_df,
as.data.frame)
)
#combined_df<-read.csv(testPath)
#read in the trial data from google drive.
trials_df <-read.csv(trialPath)
#####----------Experiment Data Cleaning----------#####
#Get the last location of the player when they press the trigger and note the start time for each trial
combined_df<-combined_df %>%
group_by(Participant.ID, gender, Level) %>%
mutate(
startTime=first(Time)
) %>%
summarise_all(last)
print(csv_files_ls)
#made a mistake and there are only 46 trials with wrong indexes, so I had to fix them using this line
#combined_df$Level = combined_df$Level-2
#remove NA rows
combined_df <- na.omit(combined_df)
#merge experiment output data with the trial data
combined_df <- merge(combined_df,trials_df,by="Level")
combined_df<-combined_df %>% arrange(Participant.ID)
#find distance traveled from the origin
combined_df$PosX<-as.numeric(combined_df$PosX)
combined_df$PosZ<-as.numeric(combined_df$PosZ)
combined_df$distTraveled <- sqrt((combined_df$PosX)^2+(combined_df$PosZ)^2)
#find the distance from the target
combined_df$distFromTarget <- sqrt((combined_df$PosX-combined_df$TargetX)^2+(combined_df$PosZ-combined_df$TargetX)^2)
#find elapsed time
combined_df$Time<-as.numeric(combined_df$Time)
combined_df$startTime<-as.numeric(combined_df$startTime)
combined_df$elapsedTime<-combined_df$Time-combined_df$startTime
#rename columns for consistency
names(combined_df)[2] <- "ID"
names(combined_df)[8] <- "FacingAngle"
#round the data values to 2 decimal places
combined_df <- combined_df %>% mutate_if(is.numeric, ~round(., 2))
#select relevant fields
output_data<-combined_df %>%
select(ID,Level,gender,PosX,PosZ,FacingAngle,distTraveled,distFromTarget,elapsedTime,PerspectiveShift,WalkingDirection,TravelDistance)
write.csv(output_data, "PilotData.csv")
combined_df<-read.csv(testPath)
trials_df <-read.csv(trialPath)
#####----------Experiment Data Cleaning----------#####
#Get the last location of the player when they press the trigger and note the start time for each trial
combined_df<-combined_df %>%
group_by(Participant.ID, gender, Level) %>%
mutate(
startTime=first(Time)
) %>%
summarise_all(last)
print(csv_files_ls)
#made a mistake and there are only 46 trials with wrong indexes, so I had to fix them using this line
#combined_df$Level = combined_df$Level-2
#remove NA rows
combined_df <- na.omit(combined_df)
#merge experiment output data with the trial data
combined_df <- merge(combined_df,trials_df,by="Level")
combined_df<-combined_df %>% arrange(Participant.ID)
#find distance traveled from the origin
combined_df$PosX<-as.numeric(combined_df$PosX)
combined_df$PosZ<-as.numeric(combined_df$PosZ)
combined_df$distTraveled <- sqrt((combined_df$PosX)^2+(combined_df$PosZ)^2)
#find the distance from the target
combined_df$distFromTarget <- sqrt((combined_df$PosX-combined_df$TargetX)^2+(combined_df$PosZ-combined_df$TargetX)^2)
#find elapsed time
combined_df$Time<-as.numeric(combined_df$Time)
combined_df$startTime<-as.numeric(combined_df$startTime)
combined_df$elapsedTime<-combined_df$Time-combined_df$startTime
#rename columns for consistency
names(combined_df)[2] <- "ID"
names(combined_df)[8] <- "FacingAngle"
#round the data values to 2 decimal places
combined_df <- combined_df %>% mutate_if(is.numeric, ~round(., 2))
#select relevant fields
output_data<-combined_df %>%
select(ID,Level,gender,PosX,PosZ,FacingAngle,distTraveled,distFromTarget,elapsedTime,PerspectiveShift,WalkingDirection,TravelDistance)
write.csv(output_data, "PilotData.csv")
View(combined_df)
setwd("C:/Users/recve/ViewPoint_Transformation_Task/")
thePath = "C:/Users/recve/ViewPoint_Transformation_Task/"
trialPath="C:/Users/recve/TrialsForDataProcessing.csv"
testPath= "C:/Users/recve/ViewPoint_Transformation_Task/0915_Mable_0915.csv"
## ---------------------------
## load up the packages
## use install.packages() to install new packages
library(plyr)
library(dplyr)
library(tidyverse)
library(reshape2)
## ---------------------------
#####----------Load Experiment Data----------#####
## read csv files
csv_files_ls <- list.files(
path=thePath,
pattern = "*.csv")
csv_files_df <- lapply(csv_files_ls,
function(x)
{
tmp <- try(read.csv(
file = x,
header = TRUE))
if (!inherits(tmp,
'try-error'))
tmp
}
)
## combine all csv files together
combined_df <- do.call("rbind",
lapply(csv_files_df,
as.data.frame)
)
#combined_df<-read.csv(testPath)
#read in the trial data from google drive.
trials_df <-read.csv(trialPath)
#####----------Experiment Data Cleaning----------#####
#Get the last location of the player when they press the trigger and note the start time for each trial
combined_df<-combined_df %>%
group_by(Participant.ID, gender, Level) %>%
mutate(
startTime=first(Time)
) %>%
summarise_all(last)
print(csv_files_ls)
#made a mistake and there are only 46 trials with wrong indexes, so I had to fix them using this line
#combined_df$Level = combined_df$Level-2
#remove NA rows
combined_df <- na.omit(combined_df)
#merge experiment output data with the trial data
combined_df <- merge(combined_df,trials_df,by="Level")
combined_df<-combined_df %>% arrange(Participant.ID)
#find distance traveled from the origin
combined_df$PosX<-as.numeric(combined_df$PosX)
combined_df$PosZ<-as.numeric(combined_df$PosZ)
combined_df$distTraveled <- sqrt((combined_df$PosX)^2+(combined_df$PosZ)^2)
#find the distance from the target
combined_df$distFromTarget <- sqrt((combined_df$PosX-combined_df$TargetX)^2+(combined_df$PosZ-combined_df$TargetX)^2)
#find elapsed time
combined_df$Time<-as.numeric(combined_df$Time)
combined_df$startTime<-as.numeric(combined_df$startTime)
combined_df$elapsedTime<-combined_df$Time-combined_df$startTime
#rename columns for consistency
names(combined_df)[2] <- "ID"
names(combined_df)[8] <- "FacingAngle"
#round the data values to 2 decimal places
combined_df <- combined_df %>% mutate_if(is.numeric, ~round(., 2))
#select relevant fields
output_data<-combined_df %>%
select(ID,Level,gender,PosX,PosZ,FacingAngle,distTraveled,distFromTarget,elapsedTime,PerspectiveShift,WalkingDirection,TravelDistance)
write.csv(output_data, "PilotData.csv")
View(combined_df)
combined_df<-read.csv(testPath)
#read in the trial data from google drive.
trials_df <-read.csv(trialPath)
#####----------Experiment Data Cleaning----------#####
#Get the last location of the player when they press the trigger and note the start time for each trial
combined_df<-combined_df %>%
group_by(Participant.ID, gender, Level) %>%
mutate(
startTime=first(Time)
) %>%
summarise_all(last)
print(csv_files_ls)
#made a mistake and there are only 46 trials with wrong indexes, so I had to fix them using this line
#combined_df$Level = combined_df$Level-2
#remove NA rows
combined_df <- na.omit(combined_df)
#merge experiment output data with the trial data
combined_df <- merge(combined_df,trials_df,by="Level")
combined_df<-combined_df %>% arrange(Participant.ID)
#find distance traveled from the origin
combined_df$PosX<-as.numeric(combined_df$PosX)
combined_df$PosZ<-as.numeric(combined_df$PosZ)
combined_df$distTraveled <- sqrt((combined_df$PosX)^2+(combined_df$PosZ)^2)
#find the distance from the target
combined_df$distFromTarget <- sqrt((combined_df$PosX-combined_df$TargetX)^2+(combined_df$PosZ-combined_df$TargetX)^2)
#find elapsed time
combined_df$Time<-as.numeric(combined_df$Time)
combined_df$startTime<-as.numeric(combined_df$startTime)
combined_df$elapsedTime<-combined_df$Time-combined_df$startTime
#rename columns for consistency
names(combined_df)[2] <- "ID"
names(combined_df)[8] <- "FacingAngle"
#round the data values to 2 decimal places
combined_df <- combined_df %>% mutate_if(is.numeric, ~round(., 2))
#select relevant fields
output_data<-combined_df %>%
select(ID,Level,gender,PosX,PosZ,FacingAngle,distTraveled,distFromTarget,elapsedTime,PerspectiveShift,WalkingDirection,TravelDistance)
write.csv(output_data, "PilotData.csv")
View(combined_df)