Re: [R] Dynamic string as element name in a list

2008-03-27 Thread Henrique Dallazuanna
But, your lapply is: lapply(x$clipno, function(c){ clipname <- x$clipname out[[clipname]] <- rnorm(5) }) So, you don't use 'c' argument. On 27/03/2008, Paul Lemmens <[EMAIL PROTECTED]> wrote: > Hi, > > Sorry yes, I forgot to give comment about th

Re: [R] Dynamic string as element name in a list

2008-03-27 Thread Paul Lemmens
Hi, Sorry yes, I forgot to give comment about the lapply(). > > foo <- function(x) { > > out <- list() > > lapply(x$clipno, function(c) { > > clipname <- x$clipname > > # stuff > > > > out[[clipname]] <- rnorm(5) > > }) > > return(out) > > } > > So x is a dataframe with th

Re: [R] Dynamic string as element name in a list

2008-03-27 Thread Henrique Dallazuanna
HI, I don't understand why you're using lapply. Please provide a example of your 'x' data.frame str(x) On 27/03/2008, Paul Lemmens <[EMAIL PROTECTED]> wrote: > Hi Henrique, > > > On Thu, Mar 27, 2008 at 2:52 PM, Henrique Dallazuanna <[EMAIL PROTECTED]> > wrote: > > Try this: > > > > foo <

Re: [R] Dynamic string as element name in a list

2008-03-27 Thread Paul Lemmens
Hi Henrique, On Thu, Mar 27, 2008 at 2:52 PM, Henrique Dallazuanna <[EMAIL PROTECTED]> wrote: > Try this: > > foo <- function(x) > { > clipname <- "LK" > out <- list() > out[[clipname]] <- rnorm(5) > return(out) > } That easy ... Hadn't thought of it. But now I have a refinement in foo() f

Re: [R] Dynamic string as element name in a list

2008-03-27 Thread Henrique Dallazuanna
Try this: foo <- function(x) { clipname <- "LK" out <- list() out[[clipname]] <- rnorm(5) return(out) } On 27/03/2008, Paul Lemmens <[EMAIL PROTECTED]> wrote: > Dear all, > > I have a piece of code along the lines of > > f <- function(x) { > clipname <- "LK" # but is in real determined based

[R] Dynamic string as element name in a list

2008-03-27 Thread Paul Lemmens
Dear all, I have a piece of code along the lines of f <- function(x) { clipname <- "LK" # but is in real determined based on info in data.frame x # other manipulations return( list(clipname=list())) } My intention is to do out <- f(dat) and then (in this example) having/getting out$LK