R date m/d/y to yyyy-mm-dd -
i trying change date within dataframe correct format within r. (m/d/y correct yyyy-mm-dd).
i have data looks this
date time ph 1 1/4/1981 9:00 3.9 2 1/8/1981 8:30 3.9
etc
the name of data frame working in data.cat.ac
i tried
data.cat.ac[,1]$date <- as.date(data.cat.ac[,1]$date, "%y/%m/%d")
...but did not work.
i getting error,
$ operator invalid atomic vectors
any tips or pointers on doing wrong?
when use as.date, should not enter format want output. instead enter format in data.
as.date("1/4/1981", format="%m/%d/%y") [1] "1981-01-04"
we got lucky in case in desired output happens default output. learning purposes, let's wanted format "dd:mm:yyyy". after converting date
format did above, use:
format(x2, "%m:%d:%y") [1] "01:04:1981"
Comments
Post a Comment