[R] Beginner in R

Peter Dalgaard p.dalgaard at biostat.ku.dk
Fri Apr 22 11:01:03 CEST 2005


Norbert Billet <norbert.billet at mpl.ird.fr> writes:

> hello ( and sorry for my poor english ... )
> 
> I'm a newbie on R software and I need to obtain this kind of system :
> 
> a structure, like a liste :
> 
> my_struct <- list()
> my_struct$a <- a_value
> my_struct$b <- another_value
> my_struct$c <- one_more_value
> 
> and a function with two args : the first is a instance of the
> structure, and the second is any component of the structure (here $a,
> $b or $c) and the function will do some transformations on this
> component :
> 
> my_func <- function(a_struct, a_comp)
> {
>     a_comp <- transformationFunct(a_comp)
>      a_result <- someComputation(a_struct)
> 
>     return(a_result)      }

If I catch your drift, you're looking for something like

my_func <- function(a_struct, a_name) {
    a_struct[[a_name]]  <- transformationFunct(a_struct[[a_name]])
    someComputation(a_struct)
}


my_func(my_struct, "b")

or maybe even a loop over all components with

lapply(names(my_struct), my_func, a_struct=my_struct)



> In reallity, the structure have lot of components (+/- 40) who are
> input parameters for a time discret model and this function is to do
> selective sensitivity analysis.
> 
> Thanks in advance for this information and thanks for doing a open
> high quality software.
> 
> Norbert


-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list