Add a Datetime Column to Position 1
datetime_to_col(data, var = "datetime")
data | A dataframe or tibble. |
---|---|
var | Character string of new column name. |
library(tidyverse) test_data <- tibble(Fruits = c("Apples and pears", "Citrus – oranges, grapefruits, mandarins and limes", "Stone fruit – nectarines, apricots, peaches and plums", "Tropical and exotic – bananas and mangoes", "Berries – strawberries, raspberries, blueberries, kiwifruit and passionfruit") ) # Datetime datetime_to_col(data = test_data, var = "test_datetime")#> # A tibble: 5 x 2 #> test_datetime Fruits #> <dttm> <chr> #> 1 2021-01-07 00:01:54 Apples and pears #> 2 2021-01-07 00:01:54 Citrus – oranges, grapefruits, mandarins and limes #> 3 2021-01-07 00:01:54 Stone fruit – nectarines, apricots, peaches and plums #> 4 2021-01-07 00:01:54 Tropical and exotic – bananas and mangoes #> 5 2021-01-07 00:01:54 Berries – strawberries, raspberries, blueberries, kiwifru…#> # A tibble: 5 x 2 #> test_date Fruits #> <date> <chr> #> 1 2021-01-07 Apples and pears #> 2 2021-01-07 Citrus – oranges, grapefruits, mandarins and limes #> 3 2021-01-07 Stone fruit – nectarines, apricots, peaches and plums #> 4 2021-01-07 Tropical and exotic – bananas and mangoes #> 5 2021-01-07 Berries – strawberries, raspberries, blueberries, kiwifruit and pa…