Re: [R] as.date

From: Joris Meys <jorismeys_at_gmail.com>
Date: Tue, 01 Jun 2010 18:06:08 +0200

Change this line to :

>pose$CREATED.DATE=as.Date(pose$CREATED.DATE,"%d/%m/%Y") # mind the capital
Y
>pose

  DESCRIPTION CREATED.DATE QUANITY CLOSING.PRICE

1 COTTON NO.2 Jul/10   2010-05-13       1       81.2000
2 COTTON NO.2 Jul/10   2010-05-13       1       81.2000
3   PALLADIUM Jun/10   2010-05-14      -1      503.6000
4   PALLADIUM Jun/10   2010-05-14      -1      503.6000
5 SUGAR NO.11 Jul/10   2010-05-10       1       13.8900
6 SUGAR NO.11 Jul/10   2010-05-10       1       13.8900

Cheers
Joris

On Tue, Jun 1, 2010 at 5:57 PM, arnaud Gaboury <arnaud.gaboury_at_gmail.com>wrote:

> Dear group,
>
> Here is my df (obtained with a read.csv2()):
>
>
> df <-
> structure(list(DESCRIPTION = c("COTTON NO.2 Jul/10", "COTTON NO.2 Jul/10",
> "PALLADIUM Jun/10", "PALLADIUM Jun/10", "SUGAR NO.11 Jul/10",
> "SUGAR NO.11 Jul/10"), CREATED.DATE = c("13/05/2010", "13/05/2010",
> "14/05/2010", "14/05/2010", "10/05/2010", "10/05/2010"), QUANITY = c(1,
> 1, -1, -1, 1, 1), CLOSING.PRICE = c("81.2000", "81.2000", "503.6000",
> "503.6000", "13.8900", "13.8900")), .Names = c("DESCRIPTION",
> "CREATED.DATE", "QUANITY", "CLOSING.PRICE"), row.names = c(NA,
> 6L), class = "data.frame")
>
> > str(df)
> 'data.frame': 6 obs. of 4 variables:
> $ DESCRIPTION : chr "COTTON NO.2 Jul/10" "COTTON NO.2 Jul/10" "PALLADIUM
> Jun/10" "PALLADIUM Jun/10" ...
> $ CREATED.DATE : chr "13/05/2010" "13/05/2010" "14/05/2010" "14/05/2010"
> ...
> $ QUANITY : num 1 1 -1 -1 1 1
> $ CLOSING.PRICE: chr "81.2000" "81.2000" "503.6000" "503.6000" ...
>
> I want to change the class of df$CREATED.DATE from Chr to Date:
>
>
> >pose$CREATED.DATE=as.Date(pose$CREATED.DATE,"%d/%m/%y")
>
> Here is what I get :
>
> df <-
> structure(list(DESCRIPTION = c("COTTON NO.2 Jul/10", "COTTON NO.2 Jul/10",
> "PALLADIUM Jun/10", "PALLADIUM Jun/10", "SUGAR NO.11 Jul/10",
> "SUGAR NO.11 Jul/10"), CREATED.DATE = structure(c(18395, 18395,
> 18396, 18396, 18392, 18392), class = "Date"), QUANITY = c(1,
> 1, -1, -1, 1, 1), CLOSING.PRICE = c("81.2000", "81.2000", "503.6000",
> "503.6000", "13.8900", "13.8900")), .Names = c("DESCRIPTION",
> "CREATED.DATE", "QUANITY", "CLOSING.PRICE"), row.names = c(NA,
> 6L), class = "data.frame")
>
> Where does the problem comes from?? Maybe from my sytem date ??
>
> TY for any help
>
> ______________________________________________
> 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.
>

-- 
Joris Meys
Statistical Consultant

Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

Coupure Links 653
B-9000 Gent

tel : +32 9 264 59 87
Joris.Meys_at_Ugent.be
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

	[[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.
Received on Tue 01 Jun 2010 - 16:09:25 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 01 Jun 2010 - 16:10:26 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive