I have values a string containing a date "01/01/2000" I want to separate the day, month and year.
#Data
#01/01/2000
#Dia Mês Ano
#01 01 2000
How do I do this in R?
I have values a string containing a date "01/01/2000" I want to separate the day, month and year.
#Data
#01/01/2000
#Dia Mês Ano
#01 01 2000
How do I do this in R?
Try this way:
unlist(strsplit("01/01/2000", "[/]"))
or
> strsplit("01/01/2000", "/")
For any string-related transformation I suggest stringr
.
The function str_split
always returns a list, regardless if it receives a vector with 1 or more elements.
> stringr::str_split(rep('01/01/2000', 5), '/')
[[1]]
[1] "01" "01" "2000"
[[2]]
[1] "01" "01" "2000"
[[3]]
[1] "01" "01" "2000"
[[4]]
[1] "01" "01" "2000"
[[5]]
[1] "01" "01" "2000"