Skip to content

lapply and dynamically linked functions

6 messages · Liaw, Andy, Carlos Mauricio Cardeal Mendes, Marc Schwartz +3 more

#
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
------------------------------------------------------------------------------
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:
See ?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:
#
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:
Error in get(x, envir, mode, inherits) : variable "mylist" was not found
[[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:

            
1 day later
#
--- Mauricio Cardeal <mcardeal at ufba.br> wrote:
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
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