[R] DAtes

arun smartpink111 at yahoo.com
Sat Aug 4 19:34:02 CEST 2012


HI,
I guess this will be more appropriate:

tfr<-read.table(text="
14/12/2000  15/12/2000  18/12/2000  19/12/2000  20/12/2000  21/12/2000
22/12/2000  25/12/2000  26/12/2000  27/12/2000  28/12/2000  29/12/2000
01/01/2001  02/01/2001  03/01/2001  04/01/2001  05/01/2001  08/01/2001
09/01/2001  10/01/2001  11/01/2001  12/01/2001  15/01/2001  16/01/2001
17/01/2001  18/01/2001  19/01/2001  22/01/2001  23/01/2001  24/01/2001
25/01/2001  26/01/2001  29/01/2001  30/01/2001  31/01/2001  01/02/2001
02/02/2001  05/02/2001  06/02/2001  07/02/2001  08/02/2001  09/02/2001
12/02/2001  13/02/2001  14/02/2001  15/02/2001  16/02/2001  19/02/2001
20/02/2001  21/02/2001
",sep="",header=FALSE,fill=TRUE,stringsAsFactors=FALSE)

tfr1<-data.frame(dates=c(tfr[,1],tfr[,2],tfr[,3],tfr[,4],tfr[,5],tfr[,6]))
tfr2<-tfr1[-c(27,36,45),]
 
head(data.frame(dates=as.Date(tfr2,format="%d/%m/%Y")))
      dates
1 2000-12-14
2 2000-12-22
3 2001-01-01
4 2001-01-09
5 2001-01-17
6 2001-01-25
# or you can do this:
 tfr1<-as.vector(c(tfr[,1],tfr[,2],tfr[,3],tfr[,4],tfr[,5],tfr[,6]))
 tfr2<-as.data.frame(as.Date(tfr1,format="%d/%m/%Y"))
 colnames(tfr2)<-"dates"
 head(tfr2)
       dates
1 2000-12-14
2 2000-12-22
3 2001-01-01
4 2001-01-09
5 2001-01-17
6 2001-01-25
A.K.



----- Original Message -----
From: Trying To learn again <tryingtolearnagain at gmail.com>
To: r-help at r-project.org
Cc: 
Sent: Saturday, August 4, 2012 12:09 PM
Subject: [R] DAtes

Hi all,

I´m trying to convert as a data frame (with format "date") this copied
excel column of dates (exposed below), I have tried to save them in a txt
file

tfr<-read.table("tfra.txt")
tfr<-data.frame(tfr)

I have tried several things, as date, so on, but always error.

And it makes
Error en as.Date.default(tfr, "%m/%d/%y") :

  do not know how to convert 'a' to class "Date"


Can anyone give me a clue or a gide to achieve this final result.












14/12/2000  15/12/2000  18/12/2000  19/12/2000  20/12/2000  21/12/2000
22/12/2000  25/12/2000  26/12/2000  27/12/2000  28/12/2000  29/12/2000
01/01/2001  02/01/2001  03/01/2001  04/01/2001  05/01/2001  08/01/2001
09/01/2001  10/01/2001  11/01/2001  12/01/2001  15/01/2001  16/01/2001
17/01/2001  18/01/2001  19/01/2001  22/01/2001  23/01/2001  24/01/2001
25/01/2001  26/01/2001  29/01/2001  30/01/2001  31/01/2001  01/02/2001
02/02/2001  05/02/2001  06/02/2001  07/02/2001  08/02/2001  09/02/2001
12/02/2001  13/02/2001  14/02/2001  15/02/2001  16/02/2001  19/02/2001
20/02/2001  21/02/2001

    [[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.




More information about the R-help mailing list