Re: [R] Loop on vector name

2008-09-18 Thread Megh Dal
]> > Subject: Re: [R] Loop on vector name > To: [EMAIL PROTECTED] > Date: Friday, September 19, 2008, 11:20 AM > hi: i'm not sure if i'm understanding your question > because the sapply > output is a vector. see below. > > > dat1 <- rnorm(5) > dat2 &l

Re: [R] Loop on vector name

2008-09-18 Thread Megh Dal
Rizopoulos <[EMAIL PROTECTED]> > Subject: Re: [R] Loop on vector name > To: [EMAIL PROTECTED] > Cc: [EMAIL PROTECTED] > Date: Wednesday, September 17, 2008, 5:32 PM > you need to get(), e.g., try this: > > dat1 <- rnorm(5) > dat2 <- rnorm(6) > dat3 <- r

Re: [R] Loop on vector name

2008-09-17 Thread Greg Snow
Others have answered the question that you asked (it is also a variation of Faq 7.21), but here is an answer to the question that you should have asked: When working with datasets like this, it is better to create a list rather than separate objects with names like dat1, dat2, etc. For example:

Re: [R] Loop on vector name

2008-09-17 Thread Dimitris Rizopoulos
you need to get(), e.g., try this: dat1 <- rnorm(5) dat2 <- rnorm(6) dat3 <- rnorm(7) lis <- lapply(paste("dat", 1:3, sep = ""), get) lis sapply(lis, sd) I hope it helps. Best, Dimitris Megh Dal wrote: [My previous message rejected, therefore I am sending same one with some modification]

Re: [R] Loop on vector name

2008-09-17 Thread Henrique Dallazuanna
Try this: sapply(ls(patt="^dat[0-9]"), function(x)sd(get(x))) On Wed, Sep 17, 2008 at 8:50 AM, Megh Dal <[EMAIL PROTECTED]> wrote: > [My previous message rejected, therefore I am sending same one with some > modification] > > I have 3 vectors with object name : dat1, dat2, dat3 > > Now I want to