[R] Strage result with an append/strptime combination

Gabor Grothendieck ggrothendieck at gmail.com
Wed Aug 29 15:22:26 CEST 2007


Try


fmt <- function(x) with(month.day.year(x),
	sprintf("%02d/%02d/%02d %02d:%02d:%02d", month, day, year,
		hours(x), minutes(x), seconds(x)))
fmt(x)


On 8/29/07, Ptit_Bleu <ptit_bleu at yahoo.fr> wrote:
>
> Thanks Gabor !
>
> It works.
> Just one more thing : is there a possibility to remove "(" and ")" before I
> copy the data to a MySQL database.
>
> Again thank you for the tip.
> Ptit Bleu.
>
>
> Gabor Grothendieck wrote:
> >
> > Try chron:
> >
> >> library(chron)
> >> namefile <- "070707050642.dat"    #day-month-year-hour-minute-second.dat
> >> x <- chron(substr(namefile, 1, 6), substr(namefile, 7, 12),
> > +   format = c("dmy", "hms"), out.format = c("m/d/y", "h:m:s"))
> >> c(x, x)
> > [1] (07/07/07 05:06:42) (07/07/07 05:06:42)
> >
> > See R News 4/1 Help Desk article for more.
> >
> >
> > On 8/29/07, Ptit_Bleu <ptit_bleu at yahoo.fr> wrote:
> >>
> >> Hi,
> >>
> >> I keep on trying to write some small scripts in order to learn R but even
> >> with basic scripts I have problems ...
> >>
> >> I start with the name of a file which is in fact the time the file has
> >> been
> >> generated (I cannot change the format). Then I convert namefile with
> >> strptime. The problem occurs when I add another time from another file
> >> with
> >> append. It displays some informations I don't want.
> >>
> >> I found a post about this problem
> >> (http://www.nabble.com/Error-with-strptime-tf3607942.html#a10081942) but
> >> I
> >> don't understand the solution. I tested as.POSIXct or as.POSIX.lt but it
> >> has
> >> no effect.
> >>
> >> Do you have some ideas to solve this problem ?
> >> Thank you for your help.
> >> Ptit Bleu.
> >>
> >> -------------------------------------------------------
> >>
> >> >namefile<-"070707050642.dat"    #day-month-year-hour-minute-second.dat
> >> >jourheure<-strptime(namefile,"%d%m%y%H%M%S")
> >>
> >> > jourheure
> >> [1] "2007-07-07 05:06:42"
> >>
> >> >jourheure<-append(jourheure,jourheure)
> >> > jourheure
> >> [1] "2007-07-07 05:06:42 Paris, Madrid (heure d'été)" "2007-07-07
> >> 05:06:42
> >> Paris, Madrid (heure d'été)"
> >>
> >> --
> >> View this message in context:
> >> http://www.nabble.com/Strage-result-with-an-append-strptime-combination-tf4347401.html#a12385852
> >> Sent from the R help mailing list archive at Nabble.com.
> >>
> >> ______________________________________________
> >> R-help at stat.math.ethz.ch 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.
> >>
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch 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.
> >
> >
>
> --
> View this message in context: http://www.nabble.com/Strage-result-with-an-append-strptime-combination-tf4347401.html#a12386702
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>



More information about the R-help mailing list