lundi 14 juin 2021

In R, how do you add a string or characters to only the first number of rows of the data frame

I have a date column as such:
id <- c(1, 2, 3) , date <- c("4 May 20", "5 June 20", "16 April 2021")

I want to add "20" to the end of the first 2 rows only and create a new column to make the dataframe look like this:

id  date               new_date
1   4 May 20           4 May 2020

2   5 June 20        5 June 2020

3   16 April 2021      16 April 2021

Aucun commentaire:

Enregistrer un commentaire