-
Notifications
You must be signed in to change notification settings - Fork 0
/
step_readData.R
54 lines (49 loc) · 1.92 KB
/
step_readData.R
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
#################################################################
################################################################
################## Read Data and ######################
################## Data Preprocessing ######################
################################################################
################################################################
# step.list returns a list of step data for each individual.
# step.mat returns concateneated step data matrix from all participants.
library(lubridate)
read_step<-function(){
step<-list()
is.wkend = vector()
step.mat = NULL
idx=1
for(file in list.files(path="./data2/minji/")){
if(endsWith(file,".RData")){
load(paste("./data2/minji/",file,sep = ""))
n<-length(foo$Steps)
toMatrix=TRUE #check if each data ends at 11:59:00 pm
for(l in 1:as.integer(n/1440)){
if(!endsWith(toString(foo[1440*l,"ActivityHour"]),"59:00")){
print(foo[1440*l,"ActivityHour"])
toMatrix=FALSE
}
}
if(toMatrix){
lct <- Sys.getlocale("LC_TIME"); Sys.setlocale("LC_TIME", "C")
A<-matrix(foo$Steps[1:(as.integer(n/1440)*1440)],nrow=1440)
#return if each date is weekends (Sun or Sat)
wkend = !(wday(as.Date(substring(matrix(foo$ActivityHour[1:(as.integer(n/1440)*1440)],nrow=1440)[1,],1,7),format = "%d%h%y" )) %in% 2:6 )
#delete days with all zero steps
if(length(which(apply(A,2,sum)==0))){
is.wkend = c(is.wkend, wkend[-which(apply(A,2,sum)==0)])
A<-A[,-which(apply(A,2,sum)==0)]
}else{
is.wkend = c(is.wkend, wkend)
}
step[[idx]]<-A
step.mat=cbind(step.mat, A)
}
idx = idx+1
}
}
return(list(step.mat = step.mat, step.list = step, is.wkend = is.wkend))
}
step0 = read_step()
step = step0$step.mat
step.list = step0$step.list
is.wkend = step0$is.wkend