converting column from a factor to date format YYYY-MM-DDThh:mm:ss.SSSZ i want to convert the whole column from a factor to date.

The str of the dataset I am using is given below:

&gt; str(dataset)
'data.frame':   2538 obs. of  5 variables:
 $ X        : int  1 2 3 4 5 6 7 8 9 10 ...
 $ SessionID: int  13307 21076 27813 8398 23118 12256 28799 11457 7542 19261 ...
 $ Timestamp: Factor w/ 2532 levels "2014-04-01T03:02:33.088Z",..: 2064 905 1086 1027 2419 1327 2035 1206 481 1354 ...
 $ ItemID   : int  214684513 214718203 214716928 214826900 214838180 214717318 214821307 214537967 214835775 214706432 ...
 $ Price    : int  0 0 0 0 0 0 0 0 0 0 ...


How  can I convert timestamp variable from factor to specific date format:


  YYYY-MM-DDThh:mm:ss.SSSZ (2014-04-06T18:42:05.823Z)
One way to do this is to use the PIPE operator to pass the column of the dataframe into your function, then assign it back to the dataframe.

I created a dataframe with one column holding your example date string five times:

&gt; x &lt;- "2014-04-06T18:42:05.823Z"
&gt; DF &lt;- as.data.frame(c(x, x, x, x, x), colnames="original")
&gt; colnames(DF) &lt;- "original"
&gt; str(DF)
'data.frame':   5 obs. of  1 variable:
 $ original: chr  "2014-04-06T18:42:05.823Z" "2014-04-06T18:42:05.823Z" 


I use this PIPE symbol, which allows you to chain methods together, passing the output from one into the input of the following. Using a . symbolises the output from the previous method.

To make the PIPE operator available, load in the magrittr package (I believe it is also included in the tidyverse, so perhaps via the dplyr package:

library(maggritr)


Now I apply the as.POSIXct function to the original column, and save it back to the dataframe in a columnn called new:

DF$new &lt;- DF$original %&gt;% as.POSIXct(., tz = "UTC", "%Y-%m-%dT%H:%M:%OS")
&gt; DF
                  original                     new
1 2014-04-06T18:42:05.823Z 2014-04-06 18:42:05.822
2 2014-04-06T18:42:05.823Z 2014-04-06 18:42:05.822
3 2014-04-06T18:42:05.823Z 2014-04-06 18:42:05.822
4 2014-04-06T18:42:05.823Z 2014-04-06 18:42:05.822
5 2014-04-06T18:42:05.823Z 2014-04-06 18:42:05.822

&gt; str(DF)
'data.frame':   5 obs. of  2 variables:
 $ original: chr  "2014-04-06T18:42:05.823Z" "2014-04-06T18:42:05.823Z" ...
 $ new     : POSIXct, format: "2014-04-06 18:42:05.822" "2014-04-06 18:42:05.822" ...


You can remove the original column if you like, using:

df$original &lt;- NULL