I have the following function defined as below

match.trace <- function(dfobj, distance, day1, day2) {
  day1 <- substitute(dfobj$day1); day1
  day2 <- substitute(dfobj$day2)
  distance <- substitute(dfobj$distance)
  xx <- NULL
  for (i in 0:10) xx[i+1] <- with(dfobj,
    cor(Lag((day1-day1[1]),i), (day2-day2[1]), use='pair'))
  i <- match(max(xx), xx)

with(dfobj, {
  mx <- max((day1-day1[1]), (day2-day2[1]), na.rm=T)
  mn <- min((day1-day1[1]), (day2-day2[1]), na.rm=T)
  cat("min=",mn, "max=",mx, "\n")
  plot(-distance, (day1-day1[1]), type='l', ylim=c(mn,mx), lwd=2, col=2, 
xaxt="n", yaxt="n")
  xscale <- pretty(-distance, 10)
  yscale <- pretty(c((day1-day1[1]), (day2-day2[1])), 10)
  axis(1, at=xscale, labels=paste(xscale))
  axis(2, at=yscale, labels=paste(yscale))
  lines(Lag(-distance,i), (day2-pste(day2)[1]), lwd=2, col=3) }
  )
}

And a dataframe with values :

  Kms Mon Tues Wed Thu Fri
1 431 525  531 518 509 519
2 430 527  539 528 514 519
3 429 533  542 536 522 526
4 428 533  541 536 523 525
5 427 535  543 539 528 527
6 426 535  542 543 532 530
...

The call to the function match.trace is

match.trace(ror31.01, Kms, Mon, Tues)

However I am getting an error because day1-day1[1] is non-numeric.  How can I 
make this work to plot out the difference in day1 initial value and the 
remainder lagged against the difference in values for the next day?

Any help would be appreciated.

Tschüß
Tony Meissner
Principal Scientist (Monitoring)
Resources Monitoring Group
Science, Monitoring and Information Division
Department of Water, Land & Biodiversity Conservation
"Imagine" ©
*(ph) (08) 8595 2209
*(mob) 0401 124 971
*(fax) (08) 8595 2232
* 28 Vaughan Terrace, Berri SA 5343
        PO Box 240, Berri SA 5343
        DX 51103
***The information in this e-mail may be confidential and/or legally 
privileged.  Use or disclosure of the information by anyone other than the 
intended recipient is prohibited and may be unlawful.  If you have received 
this e-mail in error, please advise by return e-mail or by telephoning +61 8 
8595 2209




        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to