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,130 points
34 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 in Data Analytics by anonymous
• 28,040 points
98 views
0 votes
2 answers
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 28 in Data Analytics by anonymous
• 28,040 points
57 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 in Data Analytics by anonymous
20 views
0 votes
4 answers

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

Can we create a alist as below ...READ MORE

answered Aug 5 in Data Analytics by anonymous
7,713 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,020 points
37 views
0 votes
1 answer
0 votes
2 answers

How to change column names of a Data frame?

Try this way - names(data frame) <- ...READ MORE

answered Aug 26 in Data Analytics by anonymous
• 28,040 points
79 views
0 votes
1 answer