Re: [R] A question on list and lapply

2012-12-17 Thread MacQueen, Don
If you don't need the "P" element in the output, then I think the answers you've already received are good. But if you do want to retain the "P" element, then I think it's better to simply add the missing elements back in after using lapply. The code will be easier to understand a year from now. H

Re: [R] A question on list and lapply

2012-12-14 Thread arun
uot;P") paste0("(",base,")") else tolower(base) } ) names(res1) #NULL  names(res2) #[1] "O" "P" "Q" A.K. ----- Original Message - From: William Dunlap To: arun ; Christofer Bogaso Cc: R help Sent: Friday, December 14, 2012 3:59 P

Re: [R] A question on list and lapply

2012-12-14 Thread William Dunlap
re wdunlap tibco.com > -Original Message- > From: arun [mailto:smartpink...@yahoo.com] > Sent: Friday, December 14, 2012 1:37 PM > To: William Dunlap > Cc: R help > Subject: Re: [R] A question on list and lapply > > HI, > > By applying: > bases > #$O

Re: [R] A question on list and lapply

2012-12-14 Thread William Dunlap
t; you could use this: > set.seed(51) > lapply(lapply(Dat,My_Function),function(x) > {if(names(Dat)[match.call()[[2]][[3]]]%in% > "P") NULL else x}) > A.K. > > > > > - Original Message - > From: Christofer Bogaso > To: r-help@r-project.org > Cc

Re: [R] A question on list and lapply

2012-12-14 Thread arun
Bogaso To: r-help@r-project.org Cc: Sent: Friday, December 14, 2012 1:58 PM Subject: [R] A question on list and lapply Dear all, let say I have following list: Dat <- vector("list", length = 26) names(Dat) <- LETTERS My_Function <- function(x) return(rnorm(5)) Dat1 <- lapply(Dat,

Re: [R] A question on list and lapply

2012-12-14 Thread Mark Lamias
How about Dat1 <- lapply(subset(Dat, Dat!="P"), My_Function) --Mark From: Christofer Bogaso To: r-help@r-project.org Sent: Friday, December 14, 2012 1:58 PM Subject: [R] A question on list and lapply Dear all, let say I have followi

Re: [R] A question on list and lapply

2012-12-14 Thread Sarah Goslee
What about: lapply(Dat[names(Dat) != "P"], My_Function) You could use %in% if you actually want to match a longer set of names. Sarah On Fri, Dec 14, 2012 at 1:58 PM, Christofer Bogaso wrote: > Dear all, let say I have following list: > > Dat <- vector("list", length = 26) > names(Dat) <- LETT

[R] A question on list and lapply

2012-12-14 Thread Christofer Bogaso
Dear all, let say I have following list: Dat <- vector("list", length = 26) names(Dat) <- LETTERS My_Function <- function(x) return(rnorm(5)) Dat1 <- lapply(Dat, My_Function) However I want to apply my function 'My_Function' for all elements of 'Dat' except the elements having 'names(Dat) == "