[R] Loop on vector name

Dimitris Rizopoulos d.rizopoulos at erasmusmc.nl
Wed Sep 17 14:02:12 CEST 2008


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]
> 
> I have 3 vectors with object name : dat1, dat2, dat3
> 
> Now I want to create a loop, like :
> 
> for (i in 1:3)
>    {
>     cat(sd(dati))
>    }
> 
> How I can do this in R?
> 
> Regards,
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014



More information about the R-help mailing list