In Excel, it is easy to grab a cell within a column and drag the cursor downward to replace many cells below so that each cell becomes the same value as the original.
This function can be performed in R using a for loop. I spent some time trying to figure it out today, and thought I'd share for the benefit of the next person in my shoes:
for (row in 2:length(data$column)){ # 2 so you don't affect column names
if(data$column[row] == "") { # if its empty...
data$column[row] = data$column[row-1] # ...replace with previous row's value
}
}
This worked for me, although it took a long time (5-10 mins) to run with a huge data file. Perhaps there is a more efficient way of achieving this function, and I encourage anyone to say how that could be done.
Thanks and good luck.
library(zoo)
na.locf()
is faster I believe. – Hamper