Hi Ken, Without seeing your .csv file or how you are trying to read it, it's tough to diagnose the trouble. I inserted commas between the columns in your data snippet, pasted into Excel, saved as .csv file called "datesfile.csv" in the R working directory. Then, the following worked fine for me:
junk<-read.csv("datesfile.csv", header = TRUE) junk # is a dataframe with headers Gender, DOB, etc. # Age at screening (in days): as.Date(junk$Screen.Date,format="%d %B %Y")-as.Date(junk$DOB,format="%d %B %Y") # Age at screening (in years): as.numeric(as.Date(junk$Screen.Date,format="%d %B %Y")-as.Date(junk$DOB,format="%d %B %Y"))/365.2425 I hope this helps. -Dan On Thu, Mar 10, 2016 at 11:34 AM, KMNanus <kmna...@gmail.com> wrote: > I’m trying to read in the data below from an Excel file (as a .csv file) > in order to create an age (in years.%years) but am getting the error > message in the subject line. > > I’ve tried saving the dates as dates in Excel and tried saving the dates > as text, both give me the same error message. Can someone pls tell me what > I’m doing wrong? > > Gender DOB Diagnosis Screen Date > Male 14 JULY 2012 No 05 OCTOBER 2015 > Female 31 OCTOBER 2009 No 30 NOVEMBER 2015 > Female 08 JULY 2009 No 06 DECEMBER 2015 > Male 04 JUNE 2011 NA 11 JANUARY 2016 > Female 21 AUGUST 2009 Yes 01 FEBRUARY 2016 > Male 05 NOVEMBER 2007 No 16 FEBRUARY 2016 > Male 01 JUNE 2009 NA 29 FEBRUARY 2016 > > > > Ken > kmna...@gmail.com > 914-450-0816 (tel) > 347-730-4813 (fax) > > > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. -- Dan Dalthorp, PhD USGS Forest and Rangeland Ecosystem Science Center Forest Sciences Lab, Rm 189 3200 SW Jefferson Way Corvallis, OR 97331 ph: 541-750-0953 ddalth...@usgs.gov [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.