[R] write a loop for tallies
Joris Meys
jorismeys at gmail.com
Fri Jun 25 02:11:34 CEST 2010
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.Meys at Ugent.be
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php
More information about the R-help
mailing list