[R] Get object name inside lapply
aajains at gmail.com
Thu Feb 25 22:54:24 CET 2016
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[]) for first
member of the list, and that results to NULL. However, names(c) gives
Hope that helps.
On Thu, Feb 25, 2016 at 3:27 PM, Mohammad Tanvir Ahamed via R-help <
r-help at r-project.org> wrote:
> I want to get object name of a list inside lapply
> > c<-list(a=seq(1:5),b=seq(10:20))
> > lapply(c,names)
> 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 | mashranga at yahoo.com
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help