I'm relatively new to R .I tried converting the datetime column with values like 01apr1985:00:00:00.000 using strptime(datetime,"%d%b%Y).Could anyone help me in this regard .Please reply ASAP i need . -- View this message in context: http://www.nabble.com/Datetime-conversion-tp25503138p25503138.html Sent from the R help mailing list archive at Nabble.com.
On Sep 18, 2009, at 1:03 AM, premmad wrote:> > I'm relatively new to R .I tried converting the datetime column with > values > like 01apr1985:00:00:00.000 using strptime(datetime,"%d%b%Y).Could > anyone > help me in this regard .Please reply ASAP i need .You will need to give us a more complete sample of your code, because I don't see a problem: > strptime("01apr1985:00:00:00.000","%d%b%Y") [1] "1985-04-01" also works when hours, minutes and seconds format was used:> > strptime("01apr1985:00:00:00.000","%d%b%Y:%H:%M:%S") > [1] "1985-04-01" > > strptime("01apr1985:00:00:00.000","%d%b%Y:%T") > [1] "1985-04-01" >David Winsemius, MD Heritage Laboratories West Hartford, CT
use "View" to view the dataframe. On Fri, Sep 18, 2009 at 8:17 AM, premmad <mtechprem at gmail.com> wrote:> > Thanks .I tried its working but when i tried to view the dataframe i got the > following error > Error in edit.data.frame(get(subx, envir = parent), title = subx, ...) : > ?can only handle vector and factor elements > > > -- > View this message in context: http://www.nabble.com/Datetime-conversion-tp25503138p25507734.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
On Fri, Sep 18, 2009 at 04:32:27AM -0700, premmad wrote:> > Sorry for confusing you all with my inexperienced posting . > I tried as u said if you have 9 rows in the data it is working fine but > please try out the same example as you have suggested earlier with morethan > 9 rows. > > I tried it as following > datetime <-c( > + "01OCT1987:00:00:00.000", > + "12APR2004:00:00:00.000", > + "01DEC1987:00:00:00.000", > + "01OCT1975:00:00:00.000", > + "01AUG1979:00:00:00.000", > + "26JUN2003:00:00:00.000", > + "01JAN1900:00:00:00.000", > + "13MAY1998:00:00:00.000", > + "30SEP1998:00:00:00.000", > + "30SEP1998:00:00:00.000", > + "30SEP1998:00:00:00.000", > + "30SEP1998:00:00:00.000") > dt <- as.data.frame(datetime) > > dt$date<-strptime(as.character(dt$datetime),"%d%b%Y") > > and got the following error : > > Error in `$<-.data.frame`(`*tmp*`, "date", value = list(sec = c(0, 0, : > replacement has 9 rows, data has 12.Oops - sorry you are right. There is a Problem with inserting the object. Try this instead: dt$date <- as.Date(dt$datetime, "%d%b%Y") cu Philipp -- Dr. Philipp Pagel Lehrstuhl f?r Genomorientierte Bioinformatik Technische Universit?t M?nchen Wissenschaftszentrum Weihenstephan 85350 Freising, Germany http://webclu.bio.wzw.tum.de/~pagel/
Thanks to everyone for helping me overcome the problem faced .I have got over with the problem .once again thanks for the immediate response of all the members -- View this message in context: http://www.nabble.com/Datetime-conversion-tp25503138p25530176.html Sent from the R help mailing list archive at Nabble.com.