Why don't you simply use names(c) to get the names of all objects? If, for
your purposes, you still want the "names" function inside lapply, you can
use the following:
unlist(lapply(1:length(c), function(x) names(c[x])))
This will produce exactly same output as names(c) would. When you use
lapply(c, names) then it basically does this: names(c[[1]]) for first
member of the list, and that results to NULL. However, names(c[1]) gives
you "a".

Hope that helps.

On Thu, Feb 25, 2016 at 3:27 PM, Mohammad Tanvir Ahamed via R-help <
r-help@r-project.org> 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 ?
>
> 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  |  mashra...@yahoo.com
>
> ______________________________________________
> R-help@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]]

______________________________________________
R-help@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.

Reply via email to