Message-ID: <CAM_vjukJqNPiDKmTnioYiMwrbmDqEY-ViJcLUf4P_n2Q-HnoGg@mail.gmail.com>
Date: 2012-12-14T19:09:13Z
From: Sarah Goslee
Subject: A question on list and lapply
In-Reply-To: <50CB76CA.9030800@gmail.com>
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
<bogaso.christofer at gmail.com> wrote:
> 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) == "P"'. Here I have specified the
> name "P" just for illustration however this will be some name specified by
> user.
>
> Is there any direct way to achieve this, using 'lapply'?
>
> Thanks for your help.
>
--
Sarah Goslee
http://www.functionaldiversity.org