简体   繁体   中英

Using `lapply` with a S4 object and a custom function with 2 arguments

I'm trying to execute my own function named myfun(x,y) on a S4 object using lapply() , but don't know if it's the appropriate way to do it.

My S4 object dblist contains 3 slots and I would like to fill the empty plot df.para using my function that takes in arguments df.list and df.para . (the argument df.para is used to create sub slot (eg $Name ; $Eval ...etc))

So I tried this :

> lapply(dblist@df.list, myfun(x,y) , y=dblist@df.para)  
Error: object 'x' not found

Here is a description of the object dblist :

> str(dblist)
Formal class 'dblist' [package ".GlobalEnv"] with 3 slots
  ..@ df.list :List of 102
  .. ..$ :'data.frame': 81 obs. of  3 variables:
  .. .. ..$ Parametre: Factor w/ 81 levels "1.","10.","11.",..: 77 79 76 80 74 81 75 78 1 13 ...
  .. .. ..$ valeur1  : Factor w/ 69 levels "","1/2-1/2","1522",..: 55 27 5 11 20 4 3 2 24 26 ...
  .. .. ..$ valeur2  : Factor w/ 73 levels "","]","a6","b5",..: 2 2 2 2 2 2 2 2 28 21 
...  
.. .. [list output truncated]
  ..@ df.para : list()
  ..@ df.coups: list()

I think the issue is that your lapply function is not clear enough on what the arguments to myfun are. Try this:

lapply(X=dblist@df.list, FUN=myfun(x=X,y) , y=dblist@df.para) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM