[R] Something wrong with my function Please Help

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Tue Sep 29 09:42:14 CEST 2009


On Tue, Sep 29, 2009 at 4:29 AM, Chunhao Tu <tu_chunhao at yahoo.com> 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){

 What is this line doing:

      x <- as.matrix(any(dim(x)==2))

 If you run it on your 2x2 matrix you get this:

 > as.matrix(any(dim(tt)==2))
     [,1]
[1,] TRUE

 and then the rest of your code is working with that value of 'x', and
so failing.

 I don't know what that line is there for - what do you think it is doing?

 You shouldn't get stuck for hours over something this simple. Try
each line on its own and check the return value is what you think it
should be. You can either type each line in to the > prompt, or learn
to use the 'debug' function. See help(debug) for more.

Barry




More information about the R-help mailing list