[R] getting the "name" of an object

francois Guilhaumon francoisguilhaumon at gmail.com
Wed Oct 22 16:02:30 CEST 2008


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)

}#end of createVarMean

Using :


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,


More information about the R-help mailing list