Hi @ImranJ,
A couple of comments before exploring some solutions. NA and NaN are different in R (and many other languages). NA is literally "not available", and usually represents missing data, while NaN represents "not a number". In lots of computations, they may act the same, but I think it is worth nothing that difference. Also worth pointing out that "NA" is actually just a character string and not true NA which is a special data type in R. For example:
is.na("NA")
#> [1] FALSE
is.na(NA)
#> [1] TRUE
Since your data are stored in a column, you just need to use a function that applies the requisite task on a column of a data frame. No for loop needed. Here are two solutions (there are many more ways to achieve the same thing in R):
sample <- data.frame(x1 = 1:5,
x2 = NA)
# base R
sample1 <- sample
sample1$x2 <- ifelse(is.na(sample$x2), 999, sample$x2)
sample1
#> x1 x2
#> 1 1 999
#> 2 2 999
#> 3 3 999
#> 4 4 999
#> 5 5 999
# tidyverse way
library(tidyr)
sample2 <- replace_na(sample, list(x2 = 999))
sample2
#> x1 x2
#> 1 1 999
#> 2 2 999
#> 3 3 999
#> 4 4 999
#> 5 5 999
Created on 2020-07-03 by the reprex package (v0.3.0)