I have a question concerning the conversion of dates in R. I have a data set with a date column indicating the day of job commencement in an organization in format "dd.mm.yyyy" (e.g., 01.09.2016) (Variable jobstart). As I want to calculate the tenure in years (2018-year of job commencement), I first need to convert the dates from the format dd.mm.yyyy to yyyy.
I tried the following:
data$tenure <- as.Date(data$jobstart,format="%d.%m.%Y")
as.Date(data$tenure,format="%Y")
and
data$tenure <- as.Date(data$jobstart,format="%d.%m.%Y")
format(data$tenure,"%Y")
The first one didn't work at all and for the second I got the following output:
[1] "2013" "2011" "2000" "2005" "2016" "1987" "2010" "1985"
[9] "1994" "1998" "1985" "2006" "2003" "1985" "1985" "1991"
[17] "1987" "2006" "1999" "2010" "2013" "1996" "2018" "2017"
[25] "2016" "2017" "2001" "1999" "1998" "2010" "1995" "2002"
[33] "2017" "1984" "2006" "1995" "2017" "1991" "1995" "1999"
[41] "2017" "2015" "1991" "1986" "2011" "2011" "2017"
First, I was really happy but when I looked again in the rows in the dataset, it didn't convert the dates...
Can someone help me?
Thanks in advance!