I have read through other stackoverflow questions on this topic, but I'm still lost. I think I need to use lapply, but I'm failing to see exactly how to do it.
Let's say I have the following two dataframes:
df1 <- data.frame(Color = c("Red", "Green", "Blue", "Green", "Purple", "Red"),
Year = c(1999, 2008, 2010, 2018, 2017, 2018),
License = c("123ABC", "544HGB", "923LWD", "443JFD", "889WER", "932OIF"))
df2 <- data.frame(Color = c("White", "Green", "Black", "Silver", "Purple", "Blue"),
Year = c(2013, 2008, 2004, 2012, 2017, 2019),
License = c("342UDD", "544HGB", "398KJX", "654KIR", "889WER", "874SSD"))
I want R to loop through df2, and every time it encounters a value in the license column that is not present in the license column of df1, it should append the entire row containing that license value from df2 to the top of df1 (i.e. make it the top row). Can anyone advise on the right way to do this?
c(and)?) - r2evans