Re: [R] apply function over same column of all objects in a list

2012-08-03 Thread gail
Excellent, thank you to both of you!!! Gail -- View this message in context: http://r.789695.n4.nabble.com/apply-function-over-same-column-of-all-objects-in-a-list-tp4638681p4639009.html Sent from the R help mailing list archive at Nabble.com. __ R-h

Re: [R] apply function over same column of all objects in a list

2012-08-02 Thread arun kirshna [via R]
Thanks Elk, That was the missing link. #or lapply(list6,function(x)max(x$target)) [[1]] [1] 6 [[2]] [1] 18 [[3]] [1] 9 max(unlist(lapply(list6,function(x) max(x$target A.K. ___ If you reply to this email, your message will be added to the disc

Re: [R] apply function over same column of all objects in a list

2012-08-02 Thread Eik Vettorazzi
Hi Arun, if you name the data.frame in the list, e.g. mango <- list( y=c(4,5,3,2,1,8), bw=c(4,18,12,3,4,9), nn=paste0("a",1:6),target=data.frame(coconut=1:6)) banana <- list(target=data.frame(coconut=c(1,2,18,16,15)), y=c(4,5,9,2,1), bw=c(4,18,22,3,4), nn=paste0("a",1:5)) pineapple <- list(target=d

Re: [R] apply function over same column of all objects in a list

2012-08-02 Thread arun kirshna [via R]
Hi Elk, I tried to test with another case where coconut is in different position in the sublist. mango <- list( y=c(4,5,3,2,1,8), bw=c(4,18,12,3,4,9), nn=paste0("a",1:6),data.frame(coconut=1:6)) banana <- list(data.frame(coconut=c(1,2,18,16,15)), y=c(4,5,9,2,1), bw=c(4,18,22,3,4), nn=paste0("a",1:

Re: [R] apply function over same column of all objects in a list

2012-08-02 Thread arun kirshna [via R]
Hello, I was in a hurry at the time, when I replied. You could do one thing: extract sublist using: list4 <- list(mango, banana, pineapple) b1<-list() for(i in 1:3){ b1[[i]]<-list() b1[[i]]<-list4[[i]][1] } b1 b<-list() for(i in 1:3){ b[[i]]<-list() b[[i]]<-lapply(b1[[i]][[1]],FUN=functio

Re: [R] apply function over same column of all objects in a list

2012-08-02 Thread arun kirshna [via R]
Hi Elk, Thanks for the input. Somehow, I got entangled with which.max. I should have used max. lapply(list4,function(x) max(x[[1]]$coconut)) [[1]] [1] 6 [[2]] [1] 18 [[3]] [1] 9 max(unlist(lapply(list4,function(x) max(x[[1]]$coconut #[1] 18 A.K.

Re: [R] apply function over same column of all objects in a list

2012-08-02 Thread Eik Vettorazzi
I still try to figure out, what you are finally asking for, but maybe res<-sapply(list4,function(x)max(x[[1]]$coconut)) names(res)<-c("mango", "banana", "pineapple") res max(res) is worth a try? Especially i did not get the point of doing something like x[which.max(x)] because this is in any cas

Re: [R] apply function over same column of all objects in a list

2012-08-02 Thread arun kirshna [via R]
Hello, If I understand it now, can't you do this: Individual cases: list4<-list(mango[[1]],banana[[1]],pineapple[[1]]) b<-list() for(i in 1:3){ b[[i]]<-list() b[[i]]<-lapply(list4[[i]],FUN=function(x)x[which.max(x)]) } b1<-data.frame(do.call(rbind,b)) row.names(b1)<-c("mango","banana","pineap

Re: [R] apply function over same column of all objects in a list

2012-08-02 Thread gail
Hi, my dataset is the result of the function "density" on another set of data. It refers to that data in its variable "call", though since all the results are actually reproduced (except that I've removed all rows bar 10), I am not sure why R still needs it. But I've understood now why your code d

Re: [R] apply function over same column of all objects in a list

2012-08-02 Thread gail
Michael, here is the data I am working with. I've shortened it without, I trust, changing its nature. I am not using any package other than what is pre-installed. Many thanks, Gail > dput(list.example) list (structure(list( x = c(379.455895016957, 380.116796110287, 380.777697203618, 381.438598

Re: [R] apply function over same column of all objects in a list

2012-08-02 Thread gail
Well but the whole point was to be able to plug in a single command and get the result for all sublists. If I have to create a new list and type in each sublist and the column I'm interested in, that completely defeats the purpose, I might as well just ask for max(sublist$coconut) for each sublist,

Re: [R] apply function over same column of all objects in a list

2012-08-02 Thread gail
Arun, I see you've defined dat5 in your later message; however the same applies as to the above: the code doesn't work if the list contains non-numerical elements. Gail -- View this message in context: http://r.789695.n4.nabble.com/apply-function-over-same-column-of-all-objects-in-a-list-tp4638

Re: [R] apply function over same column of all objects in a list

2012-08-02 Thread arun kirshna [via R]
Hi, I am not able to read your dataset. Getting errors. source("list1.txt") Error in paste(locuteur, i, sep = "") : object 'locuteur' not found Please check. A.K. __ If you reply to this email, your message will be added to the discussion below: http://r.7896

Re: [R] apply function over same column of all objects in a list

2012-08-02 Thread arun kirshna [via R]
Hello Gail, The dat5 was in earlier post. I forgot to paste it. Now, your question regarding individual cases, This is a case that includes nonnumeric columns list1<-list(data.frame(x=1:6,y=c(4,5,3,2,1,8),bw=c(4,18,12,3,4,9),nn=paste0("a",1:6))) list2<-list(data.frame(x=c(1,2,18,16,15),y=c(4,5,9,

Re: [R] apply function over same column of all objects in a list

2012-08-01 Thread arun kirshna [via R]
HI, I tested the code for another set of data with added complexity. Seems to be working fine. list1<-list(data.frame(x=1:6,y=c(4,5,3,2,1,8),bw=c(4,18,12,3,4,9))) list2<-list(data.frame(x=c(1,2,18,16,15),y=c(4,5,9,2,1),bw=c(4,18,22,3,4))) list3<-list(data.frame(x=c(4,6,9),y=c(8,24,12),bw=c(14,31,3

Re: [R] apply function over same column of all objects in a list

2012-08-01 Thread R. Michael Weylandt
I'm a little confused on your data structure -- can you use dput() as described here [1] to give a small reproducible example? http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example Michael On Wed, Aug 1, 2012 at 10:38 AM, gail wrote: > Thank you!!! But I realise

Re: [R] apply function over same column of all objects in a list

2012-08-01 Thread R. Michael Weylandt
On Wed, Aug 1, 2012 at 8:43 AM, gail wrote: > Hello. Please forgive me if this problem has already been posted (and solved) > by someone else ... I can't find it anywhere though it seems so very basic. > Here it is: > > I have a list comprised of several matrices, each of which has two columns. >

Re: [R] apply function over same column of all objects in a list

2012-08-01 Thread gail
Thank you!!! But I realise I've simplified my data to the point that your solution doesn't actually work -- not your fault, mine! My list is actually more complicated than what I presented it to be; it's not composed of numerical matrices but of lists, each being composed of 7 columns, the first tw