I have a dataframe where the Date column contains dates of different formats.
That is, when I import the excel into R, I get
df$Date
[1] "35826" "35854" "35885" "35915" "35946" "35976" "36007"
[8] "36038" "36068" "36099" "36129" "36160" "36191" "36219"
[15] "36250" "36280" "36311" "36341" "36372" "36403" "36433"
[22] "36464" "36494" "36525" "36556" "36585" "36616" "36646"
[29] "36677" "36707" "36738" "36769" "36799" "36830" "36860"
[36] "36891" "36922" "36950" "36981" "37011" "37042" "37072"
[43] "37103" "37134" "37164" "37195" "37225" "37256" "37287"
[50] "37315" "37346" "37376" "37407" "37437" "37468" "37499"
[57] "37529" "37560" "37590" "37621" "37652" "37680" "37711"
[64] "37741" "37772" "37802" "37833" "37864" "37894" "37925"
[71] "37955" "37986" "38017" "38046" "38077" "38107" "38138"
[78] "38168" "38199" "38230" "38260" "38291" "38321" "38352"
[85] "38383" "38411" "38442" "38472" "38503" "38533" "38564"
[92] "38595" "38625" "38656" "38686" "38717" "38748" "38776"
[99] "38807" "38837" "38868" "38898" "38929" "38960" "38990"
[106] "39021" "39051" "39082" "39113" "39141" "39172" "39202"
[113] "39233" "39263" "39294" "39325" "39355" "39386" "39416"
[120] "39447" "39478" "39507" "39538" "39568" "39599" "39629"
[127] "39660" "39691" "39721" "39752" "39782" "39813" "39844"
[134] "39872" "39903" "39933" "39964" "39994" "40025" "40056"
[141] "40086" "40117" "40147" "40178" "40209" "40237" "40268"
[148] "40298" "40329" "40359" "40390" "40421" "40451" "40482"
[155] "40512" "40543" "40574" "40602" "40633" "40663" "40694"
[162] "40724" "40755" "40786" "40816" "40847" "40877" "40908"
[169] "40939" "40968" "40999" "41029" "41060" "41090" "41121"
[176] "41152" "41182" "41213" "41243" "41274" "41305" "41333"
[183] "41364" "41394" "41425" "41455" "41486" "41517" "41547"
[190] "41578" "41608" "41639" "41670" "41698" "41729" "41759"
[197] "41790" "41820" "41851" "41882" "41912" "41943" "41973"
[204] "42004" "42035" "42063" "42094" "42124" "42155" "42185"
[211] "42216" "42247" "42277" "42308" "42338" "42369" "42400"
[218] "42429" "42460" "42490" "42521" "42551" "42582" "42613"
[225] "42643" "42674" "42704" "42735" "42766" "42794" "42825"
[232] "42855" "42886" "42916" "42947" "42978" "43008" "43039"
[239] "43069" "43100" "43131" "43159" "43190" "43220" "43251"
[246] "43281" "43312" "43343" "43373" "43404" "43434" "43465"
[253] "43496" "43524" "43555" "43585" "43616" "43646" "43677"
[260] "43708" "30-Sep-2019" "31-Oct-2019" "30-Nov-2019" "31-Dec-2019" "31-Jan-2020" "29-Feb-2020"
[267] "31-Mar-2020" "30-Apr-2020" "31-May-2020" "30-Jun-2020" "31-Jul-2020" "31-Aug-2020" "30-Sep-2020"
[274] "31-Oct-2020" "30-Nov-2020" "31-Dec-2020" "31-Jan-2021" "28-Feb-2021" "44286" "30-Apr-2021"
[281] "31-May-2021" "30-Jun-2021" "31-Jul-2021" "31-Aug-2021" "30-Sep-2021" "31-Oct-2021" "30-Nov-2021"
[288] "31-Dec-2021" "31-Jan-2022" "28-Feb-2022" "31-Mar-2022" "30-Apr-2022" "31-May-2022" "30-Jun-2022"
[295] "31-Jul-2022" "31-Aug-2022" "30-Sep-2022" "31-Oct-2022" "30-Nov-2022" "31-Dec-2022" "31-Jan-2023"
[302] "28-Feb-2023" "31-Mar-2023" "30-Apr-2023" "31-May-2023" "30-Jun-2023" "31-Jul-2023" "31-Aug-2023"
[309] "30-Sep-2023" "31-Oct-2023" "30-Nov-2023" "31-Dec-2023"
I want to convert this Date column to a new Data column that will contain only the years and the months in this format “3-1998”, etc.
I saw from previous threads some potential solutions, for example
format(as.Date(df$Date), "%m/%Y")
but with no success.
Could you help me with that?