How can I remove the first elements from a variable, especially if this variable has a special characters. For example, I have the following column:
Date 01/01/2009 01/01/2010 01/01/2011 01/01/2012
I need to have a new column like the following:
Date 2009 2010 2011 2012
As discussed in the comments, this can be achieved by converting the entry into Date
format and extracting the year, for instance like this:
format(as.Date(df1$Date, format="%d/%m/%Y"),"%Y")
library(lubridate) a=mdy(b) year(a)
https://cran.r-project.org/web/packages/lubridate/vignettes/lubridate.html http://vita.had.co.nz/papers/lubridate.pdf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With