[R] Help with IF operator

ADias diasandre at gmail.com
Thu Jan 6 21:21:33 CET 2011


Hi,

I am with a problem on how to do a comparison of values. My script is as
follows:

repeat{
cat("How many teams to use? (to end write 0) ")
nro<-scan(n=1)
if(nro==0)break
cat("write the", nro, "teams names \n")
teams<-readLines(n=nro)
if (teams[1]==teams[2)next 
else print(teams)
}

On this example I only compare teams 1 name with teams 2 name, and if they
are the same the scrip starts again. If I had 10 teams how could I make it
compare the "nro" number of teams names in order to check if the same name
has been written more then once? The idea is, if the same name is written
more then once it should give an error and start the scrip again by asking
the teams names again.

Two more things: With the next function the script stats from top, I mean
starts by asking the number of teams to use. Can I make it that it goes
directly to asking teams names?
And when it checks anc find out that a certain name has been written twice
can it produce a message warning that this error happened before asking the
teams names again?

Many thanks

Regards,
A.Dias.
-- 
View this message in context: http://r.789695.n4.nabble.com/Help-with-IF-operator-tp3178129p3178129.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list