[R] Date problem

Mr Natural drstrong at ucdavis.edu
Wed Jul 18 03:10:53 CEST 2007

Dear Natalia:
I have had the same problem. Solved it by keeping my dates in Excel files
with the rest of my data. When I want to do something in R, highlight the
date column and format it as "general" You will get a 5 digit number that
represents the Julian date (more digits if you have minutes and seconds).
Save the Excel file as a csv file.
Then read it into R making the variables all numeric, with use of
eg. from a big file  that Im working on now,

"numeric","numeric","numeric",na.rm=T ))

Then you make the Julian dates back into calendar dates that plot so nicely
in R.
In my file, I have one date column for every y variable because each has a
different sequence of dates.
Note that Excel and R have a different Julian "day 1." Excel is Jan 1 1900,
and R is Jan 1 1970.
You set the day one Julian date in R with the origin feature in the dates().

The six interesting "y" variables (MP,C,D,UD,LD,and BS) each have two date
columns, the most interesting of which is the calendar date, which are made
from the Julian dates that I read in.

dmp<-dates(ss$MPdate,origin=c(month = 1, day = 1, year = 1900))
dc<-dates(ss$Cdate,origin=c(month = 1, day = 1, year = 1900))
dd<-dates(ss$Ddate,origin=c(month = 1, day = 1, year = 1900))
dld<-dates(ss$LDdate,origin=c(month = 1, day = 1, year = 1900))
dud<-dates(ss$UDdate,origin=c(month = 1, day = 1, year = 1900))
dbs<-dates(ss$BSdate,origin=c(month = 1, day = 1, year = 1900))

Then, I plot a stack of 6 time series, one on top of each other.
Note that I used "arrow" for error bars.
#stack of plots, one for each site.

par(mar=c(2,2,1,1), mfrow = c(6,1))
plot(MP~dmp, type="b",xlab="",ylim=c(0,1),xaxt = "n")
plot(C~dc, type="b",xlab="",ylim=c(0,1),xaxt = "n")
plot(D~dd, type="b",xlab="",ylim=c(0,1),xaxt = "n")
plot(LD~dld, type="b",xlab="",ylim=c(0,1),xaxt = "n")
plot(UD~dud, type="b",xlab="",ylim=c(0,1),xaxt = "n")
plot(BS~dbs, type="b",xlab="",ylim=c(0,1))

I hope this helps, 

natalia norden wrote:
> Hello,
> I have some "stupid" problems managing "date" data.
> I have a colomn "date", which I converted from a character representation:
> for example:
> a="26/02/06"
> date=strptime(a,format="%d/%m/%y")
> For one part of the analysis, I'm interested only in the month and the 
> year, so I did:
> m.y=strftime(date,format="%m/%y")
> This returns me "02/06", but this is an object of class "character" and 
> I can't convert it into an object of class "Date". Doing 
> strptime(m.y,format="%m/%y") or as.Date(m.y,format="%m/%y") returns me NA
> How can a convert this colomn "m.y" in a Date class?
> Actually, I need it to plot fruiting data against time (month and year).
> Because I have many values of seeds in a month, I used the function
> tapply:
> seeds=tapply(data$seed,data$m.y,sum)
> But plot(x=names(seeds),y=seeds) doesn't work. Does anyone know an 
> easier way?
> Thank you for your time,
> natalia
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

View this message in context: http://www.nabble.com/Date-problem-tf1280528.html#a11660658
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list