How do I convert a factor into date format

0 votes
I imported a CSV file containing dates from a SQL query, however the dates are actually date-time values, which R does not recognise:

> mydate

1/15/2006 0:00:00 0:00:00 0:00:00 0:00:00 0:00:00 0:00:00

Levels: 2373 0:00:00 1/1/2006 0:00:00 0:00:00 1/1/2007 0:00:00 0:00:00 1/1/2008 0:00:00... 0:00:00 on September 9, 2012

> the class (mydate)

"Factor" is the first word that comes to mind.

as.Date > (mydate)

charToDate(x) has an error:

The character string is not in an unambiguous standard format.

What is the best way to convert mydate to date format? (It's not necessary for me to mention the time component.)
Jun 21, 2022 in Data Analytics by avinash
• 1,840 points
571 views

1 answer to this question.

0 votes
That was close. The as needs to have format= appended. Contact date:

mydate - factor("1/15/2006 0:00:00" as.Date(mydate, format = "% m% % d% % Y")
## [1] "2006-01-15"
answered Jun 24, 2022 by Sohail
• 3,040 points

Related Questions In Data Analytics

0 votes
1 answer

How can I convert a factor variable to numeric in R ?

A factor variable can be converted to ...READ MORE

answered Sep 19, 2018 in Data Analytics by shams
• 3,670 points
3,797 views
0 votes
1 answer

How do I convert a dataframe to a list?

For doing this first you'll have to ...READ MORE

answered Sep 19, 2018 in Data Analytics by Abhi
• 3,720 points
4,377 views
+1 vote
1 answer

How to convert a list of vectors with various length into a Data.Frame?

We can easily use this command as.data.frame(lapply(d1, "length< ...READ MORE

answered Apr 4, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,669 views
0 votes
1 answer

How to convert a text mining termDocumentMatrix into excel or csv in R?

By assuming that all the values are ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,926 views
0 votes
1 answer

Big Data transformations with R

Dear Koushik, Hope you are doing great. You can ...READ MORE

answered Dec 18, 2017 in Data Analytics by Sudhir
• 1,570 points
1,036 views
0 votes
2 answers

Transforming a key/value string into distinct rows in R

We would start off by loading the ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
1,186 views
0 votes
1 answer

Finding frequency of observations in R

You can use the "dplyr" package to ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
5,893 views
0 votes
1 answer

Left Join and Right Join using "dplyr"

The below is the code to perform ...READ MORE

answered Mar 27, 2018 in Data Analytics by Bharani
• 4,660 points
1,118 views
0 votes
1 answer

How can I create a correlation matrix in R?

An example, d <- data.frame(x1=rnorm(10), ...READ MORE

answered Jun 14, 2022 in Data Analytics by Sohail
• 3,040 points
522 views
0 votes
1 answer

How can I make a list of lists in R?

Lists of lists are simple to create. list1 ...READ MORE

answered Jun 24, 2022 in Data Analytics by Sohail
• 3,040 points
621 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP