It would help if you placed r <- 0; s <- 0 etc. outside the loop. Same goes for cat(...). And get rid of the sum(r), sum(s) and so on, that's doing nothing (r,s,... are single numbers)
This said : See Peter Langfelder's response. Cheers Joris > # see ?table for a better approach > r<-0 > s<-0 > t<-0 > u<-0 > v<-0 > > a<- for (i in 1:length(n)) { > ifelse(n[i] == "3000", r <- r+1, > ifelse(n[i] == "4000", s <- r+1, > ifelse(n[i] == "5000", t <- r+1, > ifelse(n[i] == "6000", u <- r+1, > ifelse(n[i] == "7000", v <- r+1, NA))))) > } > cat("r = ", r, "\n") > cat("s = ", s, "\n") > cat("t = ", t, "\n") > cat("u = ", u, "\n") > cat("v = ", v, "\n") -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be ------------------------------- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php ______________________________________________ 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.