[R] And Statement for two if functions

kerry1912 kerry1912 at hotmail.com
Mon Jan 30 19:55:02 CET 2012


Sorry that post was written in a bit if a rush.

I am writing a function in which I am trying to create a league table from a
data frame of rugby matches with the columns as follows: home team, away
team, home score and away score.

In rugby you can get an extra bonus point if you are the losing team and
lose by less than 7 points. So therefore in my function I am writing if the
away team loses AND loses by less than or equal to 7 points then the away
team will get an extra point, 

So ideally want to write:

if(games[i,3] > games[i,4]  AND games[i,3] <= games[i,4] + 7) {
				T[which(teams == games[i,2]),"Points"] <-
							T[which(teams == games[i,2]),"Points"] + 1}

Which is inset into a function in R where the input of the function is
'games' which will be the list of the 132 matches of rugby being analysed
and where teams is the list of 12 teams in the league. 

I wasn't sure if it was possible to write an 'if' function embedded in
another 'if' function or which method would be best to achieve this. 

Thank you. 

                 


--
View this message in context: http://r.789695.n4.nabble.com/And-Statement-for-two-if-functions-tp4341179p4342098.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list