How to change mulitiple characters in a column to a date

0 votes

There are so many columns that I want to change from multiple characters to Date. I have tried Mutate function

Here is the Sample data:

d1 = c("2018-02-07 23:00:00", "2018-06-03 00:00:01", "2018-05-09
00:00:01")
d2 = c("2018-01-11 08:41:49", "2016-09-10 08:39:48", "2016-02-17
         08:41:51")
dataf<-as.data.frame(cbind(col1,col2))

Got an error by using mutate:

dataf<- dataf %>% mutate (dataf, funs(ymd))
Apr 3, 2018 in Data Analytics by DataKing99
• 8,250 points
802 views

1 answer to this question.

0 votes

Firstly we have to set dataf variable to Data Frame

dataf<-as.data.frame(cbind(d1,d2))

dataf$d1<-as.Date(dataf$d1)
dataf$d2<-as.Date(dataf$d2)

Now our Mulitiple characters have been change to Date Format 

 d1         d2
1 2018-02-07 2018-01-11
2 2018-06-03 2016-09-10
3 2018-05-09 2016-02-17

By str (Structure) commad we can verify

'data.frame':	3 obs. of  2 variables:
 $ d1: Date, format: "2018-02-07" "2018-06-03" ...
 $ d2: Date, format: "2018-01-11" "2016-09-10" ...
answered Apr 3, 2018 by DeepCoder786
• 1,720 points

Related Questions In Data Analytics

0 votes
2 answers

How to subset rows containing NA in a chosen column of a data frame?

You can give this a try. subset(dataframe, is.na(dataframe$col2)) ...READ MORE

answered Aug 21, 2019 in Data Analytics by anonymous
• 33,030 points
10,513 views
+1 vote
3 answers

How to change the value of a variable using R programming in a data frame?

Try this: df$symbol <- as.character(df$symbol) df$symbol[df$sym ...READ MORE

answered Jan 11, 2019 in Data Analytics by Tyrion anex
• 8,700 points
35,870 views
0 votes
1 answer

How to replace all occurrences of a character in a character column in a data frame in R

If you used sub() to replace the ...READ MORE

answered Jun 29, 2019 in Data Analytics by anonymous
• 33,030 points
17,972 views
0 votes
1 answer

How to create a date variable in R?

Create a string with date notation as ...READ MORE

answered Jul 16, 2019 in Data Analytics by anonymous
8,336 views
+1 vote
5 answers

How to remove NA values with dplyr::filter()

Try this: df %>% filter(!is.na(col1)) READ MORE

answered Mar 26, 2019 in Data Analytics by anonymous
332,266 views
0 votes
1 answer
0 votes
1 answer

How can I use parallel so that it preserves the list of data frames

You can use pmap as follows: nc <- ...READ MORE

answered Apr 4, 2018 in Data Analytics by kappa3010
• 2,090 points
1,106 views
0 votes
1 answer
+1 vote
3 answers

How to change column names of a Data frame?

Hi, To change the name of a column ...READ MORE

answered Oct 30, 2020 in Data Analytics by MD
• 95,460 points
1,753 views
0 votes
1 answer

How to delete DataFrame row in pandas based upon a column value?

You can use drop function in your ...READ MORE

answered May 3, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Jun 9, 2020 by MD 1,651 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