factor to date returns NA

Multi tool use
up vote
-3
down vote
favorite
I am sorry but I struggle with this:
mydate <- factor("2016-10-25")
as.Date(mydate, format = "%Y-%M-%D")
it returns NA. Any ideas? Thanks!
r
add a comment |
up vote
-3
down vote
favorite
I am sorry but I struggle with this:
mydate <- factor("2016-10-25")
as.Date(mydate, format = "%Y-%M-%D")
it returns NA. Any ideas? Thanks!
r
Tryas.Date(mydate, format = "%Y-%m-%d")
. Some more info on the formats here: statmethods.net/input/dates.html
– AntoniosK
2 days ago
Similar answer here: [link]stackoverflow.com/questions/17496358/…
– Jamie_D
2 days ago
Look up format codes with?strptime
.
– jay.sf
2 days ago
umas.Date(mydate)
works just fine since that's the default ISO format it expects
– hrbrmstr
2 days ago
3
Suggesting the use oflubridate
for this example is crazy talk. It's the default ISO format and I don't think anyone rly wants to take 1250 microseconds to do the conversion (for one element) when the built-inas.Date()
does it in 30 microseconds.
– hrbrmstr
2 days ago
add a comment |
up vote
-3
down vote
favorite
up vote
-3
down vote
favorite
I am sorry but I struggle with this:
mydate <- factor("2016-10-25")
as.Date(mydate, format = "%Y-%M-%D")
it returns NA. Any ideas? Thanks!
r
I am sorry but I struggle with this:
mydate <- factor("2016-10-25")
as.Date(mydate, format = "%Y-%M-%D")
it returns NA. Any ideas? Thanks!
r
r
asked 2 days ago
cs0815
5,2231975191
5,2231975191
Tryas.Date(mydate, format = "%Y-%m-%d")
. Some more info on the formats here: statmethods.net/input/dates.html
– AntoniosK
2 days ago
Similar answer here: [link]stackoverflow.com/questions/17496358/…
– Jamie_D
2 days ago
Look up format codes with?strptime
.
– jay.sf
2 days ago
umas.Date(mydate)
works just fine since that's the default ISO format it expects
– hrbrmstr
2 days ago
3
Suggesting the use oflubridate
for this example is crazy talk. It's the default ISO format and I don't think anyone rly wants to take 1250 microseconds to do the conversion (for one element) when the built-inas.Date()
does it in 30 microseconds.
– hrbrmstr
2 days ago
add a comment |
Tryas.Date(mydate, format = "%Y-%m-%d")
. Some more info on the formats here: statmethods.net/input/dates.html
– AntoniosK
2 days ago
Similar answer here: [link]stackoverflow.com/questions/17496358/…
– Jamie_D
2 days ago
Look up format codes with?strptime
.
– jay.sf
2 days ago
umas.Date(mydate)
works just fine since that's the default ISO format it expects
– hrbrmstr
2 days ago
3
Suggesting the use oflubridate
for this example is crazy talk. It's the default ISO format and I don't think anyone rly wants to take 1250 microseconds to do the conversion (for one element) when the built-inas.Date()
does it in 30 microseconds.
– hrbrmstr
2 days ago
Try
as.Date(mydate, format = "%Y-%m-%d")
. Some more info on the formats here: statmethods.net/input/dates.html– AntoniosK
2 days ago
Try
as.Date(mydate, format = "%Y-%m-%d")
. Some more info on the formats here: statmethods.net/input/dates.html– AntoniosK
2 days ago
Similar answer here: [link]stackoverflow.com/questions/17496358/…
– Jamie_D
2 days ago
Similar answer here: [link]stackoverflow.com/questions/17496358/…
– Jamie_D
2 days ago
Look up format codes with
?strptime
.– jay.sf
2 days ago
Look up format codes with
?strptime
.– jay.sf
2 days ago
um
as.Date(mydate)
works just fine since that's the default ISO format it expects– hrbrmstr
2 days ago
um
as.Date(mydate)
works just fine since that's the default ISO format it expects– hrbrmstr
2 days ago
3
3
Suggesting the use of
lubridate
for this example is crazy talk. It's the default ISO format and I don't think anyone rly wants to take 1250 microseconds to do the conversion (for one element) when the built-in as.Date()
does it in 30 microseconds.– hrbrmstr
2 days ago
Suggesting the use of
lubridate
for this example is crazy talk. It's the default ISO format and I don't think anyone rly wants to take 1250 microseconds to do the conversion (for one element) when the built-in as.Date()
does it in 30 microseconds.– hrbrmstr
2 days ago
add a comment |
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
You need to use small letters for month and day ("%Y-%m-%d"
) instead of capital letters ("%Y-%M-%D"
).
mydate <- factor("2016-10-25")
as.Date(mydate, format = "%Y-%m-%d")
"2016-10-25"
well I tried this - I think but yes this works now. Thanks!
– cs0815
2 days ago
You might want to also add the output ofmicrobenchmark::microbenchmark(base = as.Date(mydate), lubr = lubridate::ymd(mydate))
to this answer to show the stark contrast tolubridate
(also theformat
string is not necessary since it'll try the ISO format one by default)
– hrbrmstr
2 days ago
add a comment |
up vote
2
down vote
You can use lubridate
as follows:
mydate <- factor("2016-10-25")
require(lubridate)
ymd(mydate)
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
You need to use small letters for month and day ("%Y-%m-%d"
) instead of capital letters ("%Y-%M-%D"
).
mydate <- factor("2016-10-25")
as.Date(mydate, format = "%Y-%m-%d")
"2016-10-25"
well I tried this - I think but yes this works now. Thanks!
– cs0815
2 days ago
You might want to also add the output ofmicrobenchmark::microbenchmark(base = as.Date(mydate), lubr = lubridate::ymd(mydate))
to this answer to show the stark contrast tolubridate
(also theformat
string is not necessary since it'll try the ISO format one by default)
– hrbrmstr
2 days ago
add a comment |
up vote
3
down vote
accepted
You need to use small letters for month and day ("%Y-%m-%d"
) instead of capital letters ("%Y-%M-%D"
).
mydate <- factor("2016-10-25")
as.Date(mydate, format = "%Y-%m-%d")
"2016-10-25"
well I tried this - I think but yes this works now. Thanks!
– cs0815
2 days ago
You might want to also add the output ofmicrobenchmark::microbenchmark(base = as.Date(mydate), lubr = lubridate::ymd(mydate))
to this answer to show the stark contrast tolubridate
(also theformat
string is not necessary since it'll try the ISO format one by default)
– hrbrmstr
2 days ago
add a comment |
up vote
3
down vote
accepted
up vote
3
down vote
accepted
You need to use small letters for month and day ("%Y-%m-%d"
) instead of capital letters ("%Y-%M-%D"
).
mydate <- factor("2016-10-25")
as.Date(mydate, format = "%Y-%m-%d")
"2016-10-25"
You need to use small letters for month and day ("%Y-%m-%d"
) instead of capital letters ("%Y-%M-%D"
).
mydate <- factor("2016-10-25")
as.Date(mydate, format = "%Y-%m-%d")
"2016-10-25"
answered 2 days ago


Can H.
998
998
well I tried this - I think but yes this works now. Thanks!
– cs0815
2 days ago
You might want to also add the output ofmicrobenchmark::microbenchmark(base = as.Date(mydate), lubr = lubridate::ymd(mydate))
to this answer to show the stark contrast tolubridate
(also theformat
string is not necessary since it'll try the ISO format one by default)
– hrbrmstr
2 days ago
add a comment |
well I tried this - I think but yes this works now. Thanks!
– cs0815
2 days ago
You might want to also add the output ofmicrobenchmark::microbenchmark(base = as.Date(mydate), lubr = lubridate::ymd(mydate))
to this answer to show the stark contrast tolubridate
(also theformat
string is not necessary since it'll try the ISO format one by default)
– hrbrmstr
2 days ago
well I tried this - I think but yes this works now. Thanks!
– cs0815
2 days ago
well I tried this - I think but yes this works now. Thanks!
– cs0815
2 days ago
You might want to also add the output of
microbenchmark::microbenchmark(base = as.Date(mydate), lubr = lubridate::ymd(mydate))
to this answer to show the stark contrast to lubridate
(also the format
string is not necessary since it'll try the ISO format one by default)– hrbrmstr
2 days ago
You might want to also add the output of
microbenchmark::microbenchmark(base = as.Date(mydate), lubr = lubridate::ymd(mydate))
to this answer to show the stark contrast to lubridate
(also the format
string is not necessary since it'll try the ISO format one by default)– hrbrmstr
2 days ago
add a comment |
up vote
2
down vote
You can use lubridate
as follows:
mydate <- factor("2016-10-25")
require(lubridate)
ymd(mydate)
add a comment |
up vote
2
down vote
You can use lubridate
as follows:
mydate <- factor("2016-10-25")
require(lubridate)
ymd(mydate)
add a comment |
up vote
2
down vote
up vote
2
down vote
You can use lubridate
as follows:
mydate <- factor("2016-10-25")
require(lubridate)
ymd(mydate)
You can use lubridate
as follows:
mydate <- factor("2016-10-25")
require(lubridate)
ymd(mydate)
answered 2 days ago
NelsonGon
4819
4819
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53225204%2ffactor-to-date-returns-na%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
u B7hgjPXKzgGhS t4i1t9,osNd7nGggHYGsQiMZwlcyYowMU,9aSv4gkv900M6,ld
Try
as.Date(mydate, format = "%Y-%m-%d")
. Some more info on the formats here: statmethods.net/input/dates.html– AntoniosK
2 days ago
Similar answer here: [link]stackoverflow.com/questions/17496358/…
– Jamie_D
2 days ago
Look up format codes with
?strptime
.– jay.sf
2 days ago
um
as.Date(mydate)
works just fine since that's the default ISO format it expects– hrbrmstr
2 days ago
3
Suggesting the use of
lubridate
for this example is crazy talk. It's the default ISO format and I don't think anyone rly wants to take 1250 microseconds to do the conversion (for one element) when the built-inas.Date()
does it in 30 microseconds.– hrbrmstr
2 days ago