Add a Date Column to Position 1

date_to_col(data, var = "date")

Arguments

data

A dataframe or tibble.

var

Character string of new column name.

See also

mutate,select,reexports

Examples

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:52 Apples and pears #> 2 2021-01-07 00:01:52 Citrus – oranges, grapefruits, mandarins and limes #> 3 2021-01-07 00:01:52 Stone fruit – nectarines, apricots, peaches and plums #> 4 2021-01-07 00:01:52 Tropical and exotic – bananas and mangoes #> 5 2021-01-07 00:01:52 Berries – strawberries, raspberries, blueberries, kiwifru…
# Date date_to_col(data = test_data, var = "test_date")
#> # 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…