I am struggling with some data manipulation. One of the columns in my data sheet contains the date of birth, but for one location, the values are disabled for 100 years.
I gave an example of a small data frame to explain my problem: the dates for Paris / Berlin are correct, I want to change the date only for those lines with London as a place (for this example, from 2028-3-25 to 1928 -3-25).
library(lubridate)
date <- as.Date(c('1950-11-1','2028-3-25','1940-3-14'))
location <- c("Paris", "London", "Berlin")
df <- data.frame(date, location)
df$date_new <- ifelse(df$location %in% c("London"), df$date - years(100), df$date)
As you can see, I installed the lubridate package and tried using the if else statement, but that just gives me negative numbers in the new column.
The solution is probably very simple, but I can't figure it out, and it drives me crazy.
Thank!