R - Numeric to Date gives wrong value

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



R - Numeric to Date gives wrong value



I have a data frame DP with a column variable in numeric format which is a numeric representation of Date.


DP


variable



Example: 43282 corresponds to 7/1/2018 (try in excel).



But in R when I call as.Date() to convert it to date, I get the wrong date


as.Date()


DP$Time <- as.Date(DP$variable)

variable Time
1 43282 2088-07-02



What am I doing wrong here?





Thanks a lot!!. Guess origin was defaulted to '1970-01-01' I changed it to origin = '1900-01-01' and it worked
– Rifadh Zizou
Aug 10 at 21:59





1 Answer
1



If it is based on excel, then change the origin from default 1970-01-01 to 1899-12-30


origin


1970-01-01


1899-12-30


as.Date(43282, origin = '1899-12-30')
#[1] "2018-07-01"






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard