Hi!
In this dataframe, which I have data for US's states population for different time periods, I want to set the population of every state to its first available period's population:
This is my dataset:
state <- c(Alabama, Alabama, Alabama, Arkansas, Arkansas, Arkansas, Arkansas)
year<- c(1990, 1991, 1992, 2002, 2003, 2005, 2011)
population <- c(10000, 11000, 12000, 23000, 24000, 25000, 30000)
df <- data.frame( state, year, population)
I want to obtain this:
state <- c(Alabama, Alabama, Alabama, Arkansas, Arkansas, Arkansas, Arkansas)
year<- c(1990, 1991, 1992, 2002, 2003, 2005, 2011)
population <- c(10000, 10000, 10000, 23000, 23000, 23000, 23000)
df <- data.frame( state, year, population)
This is just a small fraction of my full dataset, so I need a code to not change constantly the state's name.
Thanks!