Hello,

I'm looking for a way to get the "name" of an object when it is used
within an "sapply".

More precisely, with a simple example :

I have a named list of objects :

myList = list(a=rnorm(10),b=rnorm(10),c=rnorm(10))

I would like to create a new object from each of the components of
myList using the "sapply" function, for example to get the mean of all
components of myList :

createVarMean = function(obj){

      obj.name = ******
      obj.mean = mean(obj)
      assign(obj.name,obj.mean)

}#end of createVarMean

Using :

sapply(myList,createVarMean)

Should then create all the objects.

Any idea to get the names ? Perhaps using object oriented programming
(is there an equivalent of the "this" syntax of Java in R ?) ?

I don't want to use a loop here.

thank you for your time and trouble,

François.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to