Did you run debug over your function? Load the library debug, and then run mtrace over your function.
library(debug) ? mtrace hth On Tuesday 29 September 2009 04:29:37 Chunhao Tu wrote: > Hi R users, > I try to build a function to compute odds ratio and relative risk however > something wrong. I stuck for many hours but I really don't know how to > solve it. Would someone please give me a hint? > > > OR.RR<-function(x){ > > + x <- as.matrix(any(dim(x)==2)) > + OR<-(x[1,1]*x[2,2])/(x[1,2]*x[2,1]) > + RR<-(x[1,1]/(sum(x[1,])))/(x[2,1]/(sum(x[2,]))) > + return(OR);return(RR) > + } > > > tt<-matrix(data=1:4,nrow=2,ncol=2) > > OR.RR(tt) > > Error in OR.RR(tt) : subscript out of bounds > > Many Thanks > Tu -- Corrado Topi Global Climate Change & Biodiversity Indicators Area 18,Department of Biology University of York, York, YO10 5YW, UK Phone: + 44 (0) 1904 328645, E-mail: ct...@york.ac.uk ______________________________________________ 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.