Q:

Error in charToDate(x) : character string is not in a standard unambiguous format in r

I want to convert 'date&time' format to 'date' format in R.
Existing format of date is - "yyyy-mm-dd hh:mm:ss" which I checked the structure of data, it shows 'chr'.
I want to convert in date format - "yyyy-mm-dd".
Then I want to count the dates in a 'col1'.
Q. How to convert string data to date format?
Q. How to count dates in a column?
x <- '2015-01-01 18:38:01'
Thanks All.
code:
str(data$col1)
format(as.Date(data$col1), "%d%m%Y")

A:

Here is my Answer:
code:
library(dplyr)
#data
x <- '2015-01-01 18:38:01'
#convert to date
y <- as.Date(strptime(x, "%Y-%m-%d %H:%M:%S"))
#grouping
tab <- data.frame(table(cut(y, 'day')))
#count distinct dates
count(unique(tab))

