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,100 points
15 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,700 points

Related Questions In Data Analytics

0 votes
1 answer

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

I would suggest you, to never to ...READ MORE

answered Apr 26, 2018 in Data Analytics by kappa3010
• 2,010 points
61 views
0 votes
1 answer

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$symb ...READ MORE

answered Jan 11 in Data Analytics by Tyrion anex
• 8,280 points
55 views
0 votes
1 answer

How to change y axis max in time series using R?

The axis limits are being set using ...READ MORE

answered Apr 3, 2018 in Data Analytics by darklord
• 6,140 points
55 views
0 votes
1 answer

With the help of tidyverse: how to rename a column to a variable name

With the help of Dplyr: rename function ...READ MORE

answered Apr 3, 2018 in Data Analytics by DeepCoder786
• 1,700 points

edited Apr 3, 2018 by DeepCoder786 25 views
0 votes
3 answers

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

Null values have no notion of equality ...READ MORE

answered Apr 11 in Data Analytics by Zane
3,344 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,010 points
20 views
0 votes
1 answer
0 votes
1 answer

How to change column names of a Data frame?

Easiest way: names(prices)[1]<-paste0("old") names(prices)[2]<-paste0("new") names(prices)[3]<-paste0("best") #or by using colnames colnames(prices)<-c("old","new","best") prices old ...READ MORE

answered Apr 11, 2018 in Data Analytics by DeepCoder786
• 1,700 points
27 views
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.