I've looked around stackoverflow and couldn't find what i was looking for, so if this is a duplicate post, sorry AND I'd greatly appreciate the link!
I have two data frames: CarDF and duplicateCarDF
ID <- c(1,2,3,4,5,6,7,8)
car <- c("acura", "audi", "benz", "benz", "bmw", "toyota", "toyota", "jeep")
year <- c(2001, 2002, '2004', '2016','1999', '2017', '2017',2005)
CarDF <- data.frame(ID, car, year)
ID2 <-c(4,7)
car2 <- c("benz2", "toyota2")
year2 <- c(2016, 2017)
duplicateCarDF <- data.frame(ID = ID2, car = car2, year = year2)
My goal is to update the cars in CarDF with the updated names in duplicateCarDF based on the IDs.
I've tried the following...
CarDF$car <- ifelse(duplicateCarDF$ID %in% CarDF$ID, duplicateCarDF$car, CarDF$car )
but it changes the car names to benz2 and toyota2 alternating. I just want to update the car for ID 4 and 7.
Any help would be greatly appreciated!