I am trying to get my R code to fill in the missing names. I have looked and did not see this question is on here. I have a 502 X 3 data frame. Of which, I am only doing one column at a time. The logic should read, if the the field is not NA, then store the name and move on to the next row. If the field is NA, then fill in that field with the last stored name. Data and code snippet below. I am not certain what I am doing wrong here. Any assistance would be wonderful. Thank you in advance for your time.
The Actual Data set is located: https://pe.usps.com/text/pub28/28apc_002.htm
Basically, I copied the file into an excel document and am trying to find a quick way to fill in the blanks. I have other files that are larger that need to have this done so it would be very beneficial to be able to do it very quickly. Also a good way to learn. :)
In this example, I would like the final list to read: "lodge", "lodge", "loop", "loop", "loop", "mall", "mall", "manor", "manor", "manor", "manor"
data <- c("lodge", "lodge", "loop", NA, NA, "mall", NA, "manor", NA, NA, NA)
i = 1
data[i]
name <- data[i]
len <- length(data)
for (i in len) {
name <- data[i]
if_else(is.na(name),
data[i] <- name,
name <- data[i])
i <- i + 1
}
data