I would like to add new rows to a dataframe that I am working with, based on data that is missing from the dataframe.
Here is an example dataframe.
year <- c(2001,2001,2002,2002,2003,2004,2004,2005)
make <- c('Honda', 'Ford', 'Honda', 'Ford', 'Honda', 'Honda', 'Ford', 'Honda')
number_manufactured <- c(10, 20, 15, 47, 14, 19, 35, 9)
cars <- data.frame(year, make, number_manufactured)
I would like to add a row to the data frame for values that are missing with number_manufactured = 0, such as: (2003, Ford, 0) and (2005, Ford, 0)
My desired data frame would be this:
year <- c(2001,2001,2002,2002,2003,2003,2004,2004,2005,2005)
make <- c('Honda', 'Ford', 'Honda', 'Ford', 'Honda','Ford', 'Honda', 'Ford', 'Honda', 'Ford')
number_manufactured <- c(10, 20, 15, 47, 14, 0, 19, 35, 9, 0)
cars <- data.frame(year, make, number_manufactured)
Thanks for the help!