I have a data frame containing observations for various individuals.
The first column contains the name of the individual, and the following columns contain the observed states, whereas each column represents one month.
During the observation period, individuals are born, resulting in NA
observations before their birth, and they leave the population for a reason displayed in the last observation, resulting in NA
s following the last observation. I would like to change the NA
s before the first observation to a certain value, and change the NA
s following the leaving of the population, to the last observation.
Since the data frame comprises more than 30,000 rows and about 400 columns, I am looking for an efficient way, other than a basic ifelse()
approach.