Janesh Devkota
2013-Feb-19 17:47 UTC
[R] Converting the data in year month day hour and minutes to date
Hi , I am trying to convert the date as factor to date using "as.date" function in R. I have the date in the following format 2008-01-01 02:30 I tried to use the following command : as.Date(mydata$Date, format="%y-%m-%d ") Can somebody help me with this ? I was able to convert the format with no hour but getting difficulty with hour included. Thank you. Janesh [[alternative HTML version deleted]]
Uwe Ligges
2013-Feb-19 18:20 UTC
[R] Converting the data in year month day hour and minutes to date
On 19.02.2013 18:47, Janesh Devkota wrote:> Hi , > > > > I am trying to convert the date as factor to date using "as.date" function > in R. I have the date in the following format > > 2008-01-01 02:30 > > > > I tried to use the following command : > > as.Date(mydata$Date, format="%y-%m-%d ") > > > > Can somebody help me with this ? I was able to convert the format with no > hour but getting difficulty with hour included.as.Date is about dates, but not hours. See ?strptime for a way to convert to POSIXlt / POSIXct representations. Best, Uwe Ligges> > > > Thank you. > > > > Janesh > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Pete Brecknock
2013-Feb-19 18:23 UTC
[R] Converting the data in year month day hour and minutes to date
jdbaba wrote> Hi , > > > > I am trying to convert the date as factor to date using "as.date" function > in R. I have the date in the following format > > 2008-01-01 02:30 > > > > I tried to use the following command : > > as.Date(mydata$Date, format="%y-%m-%d ") > > > > Can somebody help me with this ? I was able to convert the format with no > hour but getting difficulty with hour included. > > > > Thank you. > > > > Janesh > > > [[alternative HTML version deleted]] > > ______________________________________________> R-help@> mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.how about as.POSIXlt("2008-01-01 02:30", format="%Y-%m-%d %H:%M") Pete -- View this message in context: http://r.789695.n4.nabble.com/Converting-the-data-in-year-month-day-hour-and-minutes-to-date-tp4659075p4659080.html Sent from the R help mailing list archive at Nabble.com.
Rui Barradas
2013-Feb-19 18:41 UTC
[R] Converting the data in year month day hour and minutes to date
Hello, Try the following. x <- "2008-01-01 02:30" as.POSIXct(x, format = "%Y-%m-%d %H:%M") Hope this helps, Rui Barradas Em 19-02-2013 17:47, Janesh Devkota escreveu:> Hi , > > > > I am trying to convert the date as factor to date using "as.date" function > in R. I have the date in the following format > > 2008-01-01 02:30 > > > > I tried to use the following command : > > as.Date(mydata$Date, format="%y-%m-%d ") > > > > Can somebody help me with this ? I was able to convert the format with no > hour but getting difficulty with hour included. > > > > Thank you. > > > > Janesh > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Jeff Newmiller
2013-Feb-19 18:45 UTC
[R] Converting the data in year month day hour and minutes to date
It is possible to squeeze a square peg into a round hole, but often you will not
be satisfied with the result. Date is for... surprise, dates. You may want to
use the chron package or the POSIXct type. The R Journal of June 2004 (Volume
4/1) "R Help Desk" column is recommended reading.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live
Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
Janesh Devkota <janesh.devkota at gmail.com> wrote:
>Hi ,
>
>
>
>I am trying to convert the date as factor to date using "as.date"
>function
>in R. I have the date in the following format
>
>2008-01-01 02:30
>
>
>
>I tried to use the following command :
>
>as.Date(mydata$Date, format="%y-%m-%d ")
>
>
>
>Can somebody help me with this ? I was able to convert the format with
>no
>hour but getting difficulty with hour included.
>
>
>
>Thank you.
>
>
>
>Janesh
>
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
John Kane
2013-Feb-19 19:25 UTC
[R] Converting the data in year month day hour and minutes to date
You need to convert the factor to character. as.Date( as.character(mydata$Date), "%Y-%m-%d") should do it. John Kane Kingston ON Canada> -----Original Message----- > From: janesh.devkota at gmail.com > Sent: Tue, 19 Feb 2013 11:47:04 -0600 > To: r-help at r-project.org > Subject: [R] Converting the data in year month day hour and minutes to > date > > Hi , > > > > I am trying to convert the date as factor to date using "as.date" > function > in R. I have the date in the following format > > 2008-01-01 02:30 > > > > I tried to use the following command : > > as.Date(mydata$Date, format="%y-%m-%d ") > > > > Can somebody help me with this ? I was able to convert the format with no > hour but getting difficulty with hour included. > > > > Thank you. > > > > Janesh > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.____________________________________________________________ FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!