[R] Converting a Date variable from character to Date
Admire Tarisirayi Chirume
@tch|rume @end|ng |rom gm@||@com
Thu Sep 29 18:35:46 CEST 2022
Kindly request assistance to *convert a Date variable from a character to
be recognized as a date*.
NB: kindly take note that the data is in a csv file called *inflation*. I
have included part of the file content herewith with the header for
My data looks like this:
I used the following command lines.
inflation.2$cpi <- as.numeric(as.character(inflation.2$cpi))
Having run the command lines above, the variable *period* in the attached
CSV file remains being read as a character variable. Kindly assist.
Alternative email: addtarris using icloud.com/TChirume using rbz.co.zw
On Thu, Sep 29, 2022 at 6:10 PM Jeff Newmiller <jdnewmil using dcn.davis.ca.us>
> Your attachment was stripped by the mailing list. The criteria for allowed
> attachments are a bit tricky to translate into actions to apply to your
> email software, so usually including part of your file in the body of the
> email is the most successful approach for communicating your problem. Be
> sure to use a text editor or the
> readLines("filename.csv") |> head() |> dput()
> functions in R to extract lines of your file for inclusion in the email.
> On September 29, 2022 8:52:30 AM PDT, Admire Tarisirayi Chirume <
> atchirume using gmail.com> wrote:
> >I kindly request for assistance to convert a Date variable from a
> >to be recognised as a date. I used the following command lines.
> >inflation[,1:2 ] #subsetting the dataframe
> >#Renaming variables
> >inflation<- rename(inflation.df,
> > cpi = CPI,
> > year=period)
> >#subsetting data April 2020 to current
> >inflation.2$cpi <- as.numeric(as.character(inflation.2$cpi))
> >* format(as.Date(inflation.2$period), "%Y-%m")*
> >Having ran the command lines above, the variable period in the attached
> >file remains being read as a character variable. Kindly assist.
> >Thank you.
> >R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >PLEASE do read the posting guide
> >and provide commented, minimal, self-contained, reproducible code.
> Sent from my phone. Please excuse my brevity.
[[alternative HTML version deleted]]
More information about the R-help