Re: [R] Get object name inside lapply

2016-02-26 Thread peter dalgaard
On 25 Feb 2016, at 22:43 , Ben Tupper wrote: > Hi, > > Using your example (note I called the list 'z')... > > z <-list(a = seq(1:5), b = seq(10:20)) > > I picture lapply as extracting each element of z like this z[[i]] - the `[[` > extracts the ith value from the context of residing in a lis

Re: [R] Get object name inside lapply

2016-02-25 Thread Ben Tupper
Hi, Using your example (note I called the list 'z')... z <-list(a = seq(1:5), b = seq(10:20)) I picture lapply as extracting each element of z like this z[[i]] - the `[[` extracts the ith value from the context of residing in a list - hence it's name is 'lost' in the new context. That's diffe

Re: [R] Get object name inside lapply

2016-02-25 Thread Aashish Jain
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

Re: [R] Get object name inside lapply

2016-02-25 Thread Rolf Turner
On 26/02/16 11:37, Huzefa Khalil wrote: If you want the object names, you should use lapply over the names: lapply(names(c), function(x) {c[[x]]}) This makes no sense at all to me; you get the same result simply by typing "c". If the OP's message is interpreted literally, all he needs to do

Re: [R] Get object name inside lapply

2016-02-25 Thread Huzefa Khalil
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 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 >

Re: [R] Get object name inside lapply

2016-02-25 Thread Uwe Ligges
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

Re: [R] Get object name inside lapply

2016-02-25 Thread Sarah Goslee
Posting in HTML makes it much harder for people to figure out your code. Maybe this will help: > c<-list(a=seq(1:5),b=seq(10:20)) > c[[1]] [1] 1 2 3 4 5 > c[[2]] [1] 1 2 3 4 5 6 7 8 9 10 11 > names(c[[1]]) NULL > names(c[[2]]) NULL On Thu, Feb 25, 2016 at 4:15 PM, Mohammad Tanvir Aha

[R] Get object name inside lapply

2016-02-25 Thread Mohammad Tanvir Ahamed via R-help
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. Th

[R] Get object name inside lapply

2016-02-25 Thread Mohammad Tanvir Ahamed via R-help
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)$aNULL $bNULL 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 A