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 -- View this message in context: http://www.nabble.com/Something-wrong-with-my-function-Please-Help-tp25656420p25656420.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.