Data into R from Excel csv file xd<-read.csv("court.dates1.txt",as.is=T, header = F)> str(xd)'data.frame': 5 obs. of 1 variable: $ V1: chr "6/6" "5/27" "5/16" "5/2" ...>xdV1 1 6/6 2 5/27 3 5/16 4 5/2 5 4/29 cdates <- as.Date(xd, format = " %m/ %d") Error in as.Date.default(xd, format = " %m/ %d") : do not know how to convert 'xd' to class "Date" Suggestions appreciated, Don -- View this message in context: http://www.nabble.com/problem-with-as.Date-tp17788563p17788563.html Sent from the R help mailing list archive at Nabble.com.
Using xd <- structure(list(V1 = c("6/6", "5/27", "5/16", "5/2")), .Names "V1", row.names = c(NA, -4L), class = "data.frame") Try:> as.Date(paste("2008", xd$V1, sep = "/"), "%Y/%m/%d")[1] "2008-06-06" "2008-05-27" "2008-05-16" "2008-05-02" See R News 4/1 article on dates. On Wed, Jun 11, 2008 at 6:22 PM, Mr Natural <drstrong at ucdavis.edu> wrote:> > Data into R from Excel csv file > xd<-read.csv("court.dates1.txt",as.is=T, header = F) > >> str(xd) > 'data.frame': 5 obs. of 1 variable: > $ V1: chr "6/6" "5/27" "5/16" "5/2" ... > > >>xd > > V1 > 1 6/6 > 2 5/27 > 3 5/16 > 4 5/2 > 5 4/29 > > cdates <- as.Date(xd, format = " %m/ %d") > > Error in as.Date.default(xd, format = " %m/ %d") : > do not know how to convert 'xd' to class "Date" > > > Suggestions appreciated, > > Don > > > -- > View this message in context: http://www.nabble.com/problem-with-as.Date-tp17788563p17788563.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. >
since it's a dataframe, use xd$V1. also, it doesn't seem like your data has a space between the / and the numbers, so take that out of the pattern: cdates <- as.Date(xd$V1, format = "%m/%d") On Wed, Jun 11, 2008 at 6:22 PM, Mr Natural <drstrong at ucdavis.edu> wrote:> > Data into R from Excel csv file > xd<-read.csv("court.dates1.txt",as.is=T, header = F) > >> str(xd) > 'data.frame': 5 obs. of 1 variable: > $ V1: chr "6/6" "5/27" "5/16" "5/2" ... > > >>xd > > V1 > 1 6/6 > 2 5/27 > 3 5/16 > 4 5/2 > 5 4/29 > > cdates <- as.Date(xd, format = " %m/ %d") > > Error in as.Date.default(xd, format = " %m/ %d") : > do not know how to convert 'xd' to class "Date" > > > Suggestions appreciated, > > Don > > > -- > View this message in context: http://www.nabble.com/problem-with-as.Date-tp17788563p17788563.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. >