1 fill_NAs = function(file)
3 dat_with_date = read.csv(file)
4 dat = dat_with_date[,-1] #get rid of date column
9 last_noNA_indices = rep(0, p)
15 # if (is.numeric(dat[line,i]))
16 if (!is.na(dat[line,i]))
18 if (last_noNA_indices[i] < line-1)
21 meanVal = ifelse(last_noNA_indices[i]>0,
22 0.5*(dat[last_noNA_indices[i],i]+dat[line,i]),
25 for (j in (last_noNA_indices[i]+1):(line-1))
28 last_noNA_indices[i] = line
34 #complete until end if needed
37 if (last_noNA_indices[i] < n)
39 for (j in (last_noNA_indices[i]+1):n)
40 dat[j,i] = dat[last_noNA_indices[i],i]
44 dat_with_date[,2:(p+1)] = dat
45 write.csv(dat_with_date, "NONA.csv", row.names=FALSE)