[R] Get object name inside lapply
Huzefa Khalil
huzefa.khalil at umich.edu
Thu Feb 25 23:37:27 CET 2016
If you want the object names, you should use lapply over the names:
lapply(names(c), function(x) {c[[x]]})
On Thu, Feb 25, 2016 at 5:25 PM, Uwe Ligges <ligges at statistik.tu-dortmund.de
> wrote:
>
>
> On 25.02.2016 22:27, Mohammad Tanvir Ahamed via R-help wrote:
>
>> Hello,
>>
>> I want to get object name of a list inside lapply
>>
>> c<-list(a=seq(1:5),b=seq(10:20))
>>> lapply(c,names)
>>>
>> $a
>> NULL
>>
>> $b
>> NULL
>>
>> Why NULL ?
>>
>
> Why should it? seq(1:5) has no names, nor has seq(10:20).
>
> Best,
> Uwe Ligges
>
>
>
>
>
>
>> but i am expecting the names of object . Any help will be appreciated .
>>
>> I want to grab the names of object inside lapply for further process.
>>
>> Thanks .
>>
>>
>> Tanvir Ahamed
>> Göteborg, Sweden | mashranga at yahoo.com
>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>>
>>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
[[alternative HTML version deleted]]
More information about the R-help
mailing list