Skip to content

Commit 1cfb66b

Browse files
authored
Refactor R code for readability and consistency
I change all = assignments to <-
1 parent 3ca7dae commit 1cfb66b

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

learners/spacewalks/my code v2.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,43 @@ fieldnames <- c("EVA #", "Country", "Crew ", "Vehicle", "Date", "Duration", "
77
library(jsonlite)
88

99
j_l <- read_json(data_f_file)
10-
data=as.data.frame(j_l[[1]])
10+
data <- as.data.frame(j_l[[1]])
1111

1212
for( i in 2:374){
13-
r = j_l[[i]]
13+
r <- j_l[[i]]
1414
print(r)
15-
data =merge(data, as.data.frame(r), all=TRUE)
15+
data <- merge(data, as.data.frame(r), all=TRUE)
1616
}
1717
#data.pop(0)
1818

1919
time <- c()
20-
date = Date()
20+
date <- as.Date(character())
2121

2222
library(lubridate)
23-
j=1
23+
j <-1
2424
for (i in rownames(data)){
2525
print(data[j, ])
2626
if (!is.na(data[j,]$duration)){
27-
tt=data[j,]$duration
27+
tt <- data[j,]$duration
2828
if(tt == ''){
2929
#do nothing
3030
}else{
31-
t=as.POSIXlt(tt,format='%H:%M')
31+
t <- as.POSIXlt(tt,format='%H:%M')
3232
ttt <- as.numeric(as.difftime(hour(t), units = 'hours')+as.difftime(minute(t), units='mins')+as.difftime(second(t), units='secs'))/(60*60)
3333
print(t,ttt)
3434
time <- c(time, ttt)
3535
if(!is.na(data[j,]$date)){
36-
date= c(date, as.Date(substr(data[j,'date'], 1, 10), format = '%Y-%m-%d'))
36+
date <- c(date, as.Date(substr(data[j,'date'], 1, 10), format = '%Y-%m-%d'))
3737

3838
}else{
3939
time <- time[1:length(time) -1]
4040
}
4141
}
4242
}
43-
j = j+1
43+
j <- j+1
4444
}
4545

46-
t=0
46+
t <- 0
4747
for(i in time)
4848
t <- c(t, t[length(t)]+i)
4949

0 commit comments

Comments
 (0)