Hi Tobias, thanks for the help, the code I am using is quite long, but basically what I tried to do was
test <- matrix(0,6,1) x <- matrix( c(50,100,200,300,900,2343) ,ncol = 1) for (i in x){ test [i] <- (i) } but this code returns NA for all the elements which are not x Tobias Verbeke-2 wrote: > >> 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 > > ______________________________________________ > R-help@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. > > -- View this message in context: http://www.nabble.com/for-cycle-with-uncontinuous-numbers-tp25630831p25633906.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@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.