[R] for cycle with uncontinuous numbers

Tobias Verbeke tobias.verbeke at gmail.com
Sun Sep 27 12:46:16 CEST 2009


> Hi nice people,

:-)

> I would like to do a for cycle but i wish it to assume only the numers 50,
> 100, 200, 300, 900 and 2343
> I tried to do something like
> 
> x <- c(50,100,200,300,900,2343)
> for (i in x){
> #.....
> }
> 
> But it didn´t work

If you would use a reproducible code example we
could point out where the error comes from;
otherwise we can only tell this should work;
try

x <- c(50,100,200,300,900,2343)
for (i in x){
   cat(i^2, "\n")
}
# 2500
# 10000
# 40000
# 90000
# 810000
# 5489649

HTH,
Tobias




More information about the R-help mailing list