Hi all, I'm trying to use lapply on a list with the following command: out<-lapply(mylist,myfun,par1=p,par2=d) (1) where myfun<-function(x,par1,par1) {.....} (2) now this function is in fact a wrapper for some Fortran code I have written so I think this might be the problem. When I call lapply() as in (1) I get the following message: Error in get(x, envir, mode, inherits) : variable "mylist" was not found but if I say do: out<-lapply(mylist,sum) it returns a nice list with the sums of the elements in the list. So after all that I guess my question is does this have to do with the fact that my function is a wrapper for my Fortran code (which works fine on its own.. and if I use a loop as opposed to lapply() )? I imagine that lapply which is a wrapper for the .Internal lapply might have some trouble with my Fortran wrapper? Is this the case or is it something dumb on my end? Any input is appreciated. Cheers, Jason
My guess is that you probably refer to `mylist' instead of `x' inside `myfun'. Please show us the entire code, rather than leave us guessing. Andy> From: Jason Nielsen > > Hi all, > > I'm trying to use lapply on a list with the following command: > > out<-lapply(mylist,myfun,par1=p,par2=d) (1) > > where > > myfun<-function(x,par1,par1) {.....} (2) > > now this function is in fact a wrapper for some Fortran code I have > written so I think this might be the problem. When I call > lapply() as in > (1) I get the following message: > > Error in get(x, envir, mode, inherits) : variable "mylist" > was not found > > but if I say do: > > out<-lapply(mylist,sum) > > it returns a nice list with the sums of the elements in the list. So > after all that I guess my question is does this have to do > with the fact > that my function is a wrapper for my Fortran code (which > works fine on its > own.. and if I use a loop as opposed to lapply() )? I > imagine that lapply > which is a wrapper for the .Internal lapply might have some > trouble with > my Fortran wrapper? Is this the case or is it something dumb > on my end? > Any input is appreciated. > > Cheers, > Jason > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments,...{{dropped}}
Hi all: Please be patient with my silly question: How can I get proportions if I have a contingency table ? I tried the table command, but I almost sure I made my usual mistakes. Thaks Mauricio
On Wed, 2004-02-11 at 08:49, Mauricio Cardeal wrote:> Hi all: > > Please be patient with my silly question: > > How can I get proportions if I have a contingency table ? > > I tried the table command, but I almost sure I made my usual mistakes. > > Thaks > > MauricioSee ?prop.table HTH, Marc Schwartz
Or look at CrossTable in package gregmisc (which actually uses prop.table) to get something like proc freq in SAS. HIH, Stefano On Wed, Feb 11, 2004 at 01:11:21PM -0600, Marc Schwartz wrote:> On Wed, 2004-02-11 at 08:49, Mauricio Cardeal wrote: > > Hi all: > > > > Please be patient with my silly question: > > > > How can I get proportions if I have a contingency table ? > > > > I tried the table command, but I almost sure I made my usual mistakes. > > > > Thaks > > > > Mauricio > > > See ?prop.table > > HTH, > > Marc Schwartz > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
That's the expected behavior, not a bug, because:> args(lapply)function (X, FUN, ...) NULL so lapply has `X' as an formal argument. Any calls to lapply() with named argument `X=...' will match to that, so the net effect is that the `X=...' part gets used by lapply() as the list to operate on, rather than pass down to `FUN'. You might want to read the relevant section of the `R Language Definition' manual. I believe the argument is deliberately named with capital `X' to avoid collision with `x'. Andy> From: Jason Nielsen > > Well I finally figured it out. After proving to myself that > it wasn't the > Fortran wrapper with a simple example I started to dig into > this. The > problem is that I was naming one of my parameters X... which > is the name > of the input value in lapply... I'm not sure if this is a bug > or just the > way it works but here is an example: > > examplegood<-function(kn,XX) > { > out<-sum(kn)*sum(XX) > out > } > > examplebad<-function(kn,X) > { > out<-sum(kn)*sum(X) > out > } > > mylist<-vector("list") > > for(i in 1:5) mylist[[i]]<-i > > a<-1:10 > > Now run lapply and you get: > > > lapply(mylist,examplebad,X=a) > Error in get(x, envir, mode, inherits) : variable "mylist" > was not found > > > lapply(mylist,examplegood,XX=a) > [[1]] > [1] 55 > > [[2]] > [1] 110 > > [[3]] > [1] 165 > > [[4]] > [1] 220 > > [[5]] > [1] 275 > > Well there you have it! > > Cheers, > Jason > > > On Wed, 11 Feb 2004, Liaw, Andy wrote: > > > My guess is that you probably refer to `mylist' instead of > `x' inside > > `myfun'. Please show us the entire code, rather than leave > us guessing. > > > > Andy > > > > > From: Jason Nielsen > > > > > > Hi all, > > > > > > I'm trying to use lapply on a list with the following command: > > > > > > out<-lapply(mylist,myfun,par1=p,par2=d) (1) > > > > > > where > > > > > > myfun<-function(x,par1,par1) {.....} (2) > > > > > > now this function is in fact a wrapper for some Fortran > code I have > > > written so I think this might be the problem. When I call > > > lapply() as in > > > (1) I get the following message: > > > > > > Error in get(x, envir, mode, inherits) : variable "mylist" > > > was not found > > > > > > but if I say do: > > > > > > out<-lapply(mylist,sum) > > > > > > it returns a nice list with the sums of the elements in > the list. So > > > after all that I guess my question is does this have to do > > > with the fact > > > that my function is a wrapper for my Fortran code (which > > > works fine on its > > > own.. and if I use a loop as opposed to lapply() )? I > > > imagine that lapply > > > which is a wrapper for the .Internal lapply might have some > > > trouble with > > > my Fortran wrapper? Is this the case or is it something dumb > > > on my end? > > > Any input is appreciated. > > > > > > Cheers, > > > Jason > > > > > > ______________________________________________ > > > R-help at stat.math.ethz.ch mailing list > > > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > > > PLEASE do read the posting guide! > > > http://www.R-project.org/posting-guide.html > > > > > > > > > > > > > -------------------------------------------------------------- > ---------------- > > Notice: This e-mail message, together with any > attachments, contains information of Merck & Co., Inc. (One > Merck Drive, Whitehouse Station, New Jersey, USA 08889), > and/or its affiliates (which may be known outside the United > States as Merck Frosst, Merck Sharp & Dohme or MSD and in > Japan, as Banyu) that may be confidential, proprietary > copyrighted and/or legally privileged. It is intended solely > for the use of the individual or entity named on this > message. If you are not the intended recipient, and have > received this message in error, please notify us immediately > by reply e-mail and then delete it from your system. > > > -------------------------------------------------------------- > ---------------- > > > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments,...{{dropped}}
--- Mauricio Cardeal <mcardeal at ufba.br> wrote:> Hi all: > > Please be patient with my silly question: > > How can I get proportions if I have a contingency table ? > > I tried the table command, but I almost sure I made my usual > mistakes. >Try the prop.table function I am also putting together R manual for epidemiologist, some of which you may find useful. It available at http://www.ucbcidp.org/courses/epiwithr.pdf Tomas> Thaks > > Mauricio > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide!http://www.R-project.org/posting-guide.html ====Tomas Aragon, MD, DrPH http://www.medepi.org/aragon Support Open Access! Visit http://www.plos.org