Hi, I have a data.frame with the following variable: $ xx :Factor w/ 66 levels "01.02.2006","01.03.2006",..: 3 3 3 3 3 3 3 3 3 now I?d like use "as.date" on it - if I comprehend the instructions on http://finzi.psych.upenn.edu/R/library/base/html/format.Date.html it should work like this: as.date(xx, "%d.%m.%Y") - but it doesn?t... the survival Package ist loaded - is there a problem with the german format? Or did I understand something wrong? Much better than tranforming the format from to data would be to import it in the right format. Is there a parameter for read.csv to get it as a date from the beginning? -- View this message in context: http://www.nabble.com/as.date---german-date-format-tp14712654p14712654.html Sent from the R help mailing list archive at Nabble.com.
Konga wrote:> Hi, > > I have a data.frame with the following variable: > $ xx :Factor w/ 66 levels "01.02.2006","01.03.2006",..: 3 3 3 3 3 3 3 3 3 > > now I?d like use "as.date" on it - if I comprehend the instructions on > http://finzi.psych.upenn.edu/R/library/base/html/format.Date.html > it should work like this: > > as.date(xx, "%d.%m.%Y") - but it doesn?t...At least as.Date() works for me for *one* of your factor labels: as.Date(factor("01.02.2006"), "%d.%m.%Y") [1] "2006-02-01" So, please read the posting guide before posting and learn that you should tell us: What is the error message? Which R version is this? What are all the labels (in order to reproduce your error)? in order to get better help. Uwe Ligges> the survival Package ist loaded - is there a problem with the german format? > Or did I understand something wrong? > > Much better than tranforming the format from to data would be to import it > in the right format. > Is there a parameter for read.csv to get it as a date from the beginning? > > > >
Uwe Ligges-3 wrote:> > > > Konga wrote: >> Hi, >> >> I have a data.frame with the following variable: >> $ xx :Factor w/ 66 levels "01.02.2006","01.03.2006",..: 3 3 3 3 3 3 3 3 >> 3 >> >> now I?d like use "as.date" on it - if I comprehend the instructions on >> http://finzi.psych.upenn.edu/R/library/base/html/format.Date.html >> it should work like this: >> >> as.date(xx, "%d.%m.%Y") - but it doesn?t... > > What is the error message? > - Fehler in as.date(mydata$xx, "%d.%m.%Y") : > Cannot coerce to date format > > Which R version is this? > -2.6.0 > > What are all the > labels (in order to reproduce your error)? > - The data.frame has 1500 objects - do you want me to print them all? Even > the 66 different levels of the factor would be a little bit much, I think. > But I printed them once, they all have the same format. > > > > > > > in order to get better help. > > Uwe Ligges > > > >> the survival Package ist loaded - is there a problem with the german >> format? >> Or did I understand something wrong? >> >> Much better than tranforming the format from to data would be to import >> it >> in the right format. >> Is there a parameter for read.csv to get it as a date from the beginning? >> >> >> >> > > ______________________________________________ > 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. > >-- View this message in context: http://www.nabble.com/as.date---german-date-format-tp14712654p14714199.html Sent from the R help mailing list archive at Nabble.com.
Konga wrote:> > Uwe Ligges-3 wrote: >> >> >> Konga wrote: >>> Hi, >>> >>> I have a data.frame with the following variable: >>> $ xx :Factor w/ 66 levels "01.02.2006","01.03.2006",..: 3 3 3 3 3 3 3 3 >>> 3 >>> >>> now I?d like use "as.date" on it - if I comprehend the instructions on >>> http://finzi.psych.upenn.edu/R/library/base/html/format.Date.html >>> it should work like this: >>> >>> as.date(xx, "%d.%m.%Y") - but it doesn?t... >> What is the error message? >> - Fehler in as.date(mydata$xx, "%d.%m.%Y") : >> Cannot coerce to date formatI see, so this is really as.data() from the survival package.>> Which R version is this? >> -2.6.0 >> >> What are all the >> labels (in order to reproduce your error)? >> - The data.frame has 1500 objects - do you want me to print them all? Even >> the 66 different levels of the factor would be a little bit much, I think. >> But I printed them once, they all have the same format.The data.frame has 1500 rows but the factor just 66 labels. You could have made it available from some web server. Anyway, you could try as.date(format(as.Date(mydata$xx, "%d.%m.%Y"), "%m/%d/%Y")) instead (discussion open for better ideas!). Uwe Ligges>> >> >> in order to get better help. >> >> Uwe Ligges >> >> >> >>> the survival Package ist loaded - is there a problem with the german >>> format? >>> Or did I understand something wrong? >>> >>> Much better than tranforming the format from to data would be to import >>> it >>> in the right format. >>> Is there a parameter for read.csv to get it as a date from the beginning? >>> >>> >>> >>> >> ______________________________________________ >> 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. >> >> >
"Functions to convert between character representations and objects of class "Date" representing calendar dates." $ xx :Factor w/ 66 levels try as.character(xx) --- Konga <ericwill75 at yahoo.de> wrote:> > Hi, > > I have a data.frame with the following variable: > $ xx :Factor w/ 66 levels > "01.02.2006","01.03.2006",..: 3 3 3 3 3 3 3 3 3 > > now I?d like use "as.date" on it - if I comprehend > the instructions on >http://finzi.psych.upenn.edu/R/library/base/html/format.Date.html> it should work like this: > > as.date(xx, "%d.%m.%Y") - but it doesn?t... > > the survival Package ist loaded - is there a problem > with the german format? > Or did I understand something wrong? > > Much better than tranforming the format from to data > would be to import it > in the right format. > Is there a parameter for read.csv to get it as a > date from the beginning? > > > > > -- > View this message in context: >http://www.nabble.com/as.date---german-date-format-tp14712654p14712654.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. >
Thanks a lot, it works! Now I have to find out why - but I think I can/should do it on my own ;o) -- View this message in context: http://www.nabble.com/as.date---german-date-format-tp14712654p14728914.html Sent from the R help mailing list archive at Nabble.com.
>> Konga wrote: >>> Hi, >>> >>> I have a data.frame with the following variable: >>> $ xx :Factor w/ 66 levels "01.02.2006","01.03.2006",..: 3 3 3 3 3 3 3 3 >>> 3 >>> >>> now I?d like use "as.date" on it - if I comprehend the instructions on >>> http://finzi.psych.upenn.edu/R/library/base/html/format.Date.html >>> it should work like this: >>> >>> as.date(xx, "%d.%m.%Y") - but it doesn?t... >> What is the error message? >> - Fehler in as.date(mydata$xx, "%d.%m.%Y") : >> Cannot coerce to date formatYou are invoking a function from the "date" library, but reading the documentation for "Date"; they are quite different. The 'date' library was written 8-10 years ago, and is used by some of the functions in the survival library (a dependence that I am currently removing). It works quite well, but has a much smaller scope of functionality than the later 'Date' library, in particular there are no attempts at multi-language support. So as.date + German format is nearly a contradiction. > args(as.date) function (x, order = "mdy", ...) So you see that the function does not even have a "format" argument. If your delimiter were one of /,- then order='dmy' would have worked, but as.date does not accept '.' Terry Therneau