[R] as.date

arnaud Gaboury arnaud.gaboury at gmail.com
Tue Jun 1 17:57:29 CEST 2010


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



More information about the R-help mailing list