Arefo Arefo - 3 months ago 28
R Question

Update a column of dates in a data frame

I got a data frame liks so:

Name | Date
A 2015-11-01
A 2015-11-02
B 2015-11-01

My dataset is quite large so how is the correct way to update the Date column with say 7 days to get:

Name | Date
A 2015-11-08
A 2015-11-09
B 2015-11-08

What is the correct way to deal with this in regards to vectorization? I kow that by using "+" on date objects one can add n days, but how can I apply this for each element in df$Date?


The simplest and nicest way is using '+' to the column as follows:

df$Date <- df$Date + 7 # This will add 7 days to all entries