5
I have a data.frame
with a column (mes) that represents the month and year of each observation that is in string form. I wanted to modify it to date so I could use proc in excel with date. How can I do it?
mes Sub_item Brasil Brasilia.DF Goiania.GO Campo_Grande.MS Salvador.BA Fortaleza.CE
1 junho 2017 3103.Cama, mesa e banho -0.73 -0.50 -0.88 -3.43 -3.37 -1.54
2 maio 2017 3103.Cama, mesa e banho -0.42 -1.75 0.90 -3.51 1.88 -1.71
3 junho 2017 4101.Roupa masculina 0.39 0.73 -1.74 0.54 1.87 -2.00
4 maio 2017 4101.Roupa masculina 0.98 -0.57 -0.61 1.02 1.72 1.06
5 junho 2017 4102.Roupa feminina 0.21 -0.15 -0.25 1.42 -0.12 1.01
6 maio 2017 4102.Roupa feminina 1.10 0.69 0.43 -1.23 0.56 0.59
7 junho 2017 4103.Roupa infantil 0.51 1.01 0.49 -1.14 0.72 -0.28
8 maio 2017 4103.Roupa infantil 1.33 0.08 0.33 2.72 0.59 -0.41
9 junho 2017 4201.Calcados e acessorios 0.05 0.48 -0.69 0.12 1.14 0.19
10 maio 2017 4201.Calcados e acessorios 0.85 0.16 0.13 0.53 1.25 1.07
11 junho 2017 4301.Joias e bijuterias -0.28 -1.42 0.27 0.96 0.40 -0.82
12 maio 2017 4301.Joias e bijuterias 0.49 1.67 -0.66 -0.74 -1.78 -2.26
13 junho 2017 4401.Tecidos e armarinho 0.36 -0.46 2.50 -0.68 -0.76 2.61
14 maio 2017 4401.Tecidos e armarinho 0.30 -0.93 1.06 0.29 1.11 0.39
I tried to use some functions like str_replace
, as.Date
. I thought of creating a function that would change each string "month year" to a date format (unfortunately I could not play).
Do you guys have any ideas? Thanks!
To use
as.Date
should first choose a day for the date, usually the day1
. Thus:as.Date(paste("1", dados$mes), "%d %B %Y")
.– Rui Barradas