Hi there, newby here.
I am trying to run a for loop to print the results in a new column. I have a data frame as so:
home / away / result
2 / 2 / NA
1 / 3 / NA
ect. The code I am using is:
for (i in 1:nrow(df))
{
if (df[i, ] == df[i, ]){
df$Result <- ("Draw")
} else if (df[i, ] < df[i, ]){
df$Result <- ("Away")
} else {
df$Result <- ("Home")
}
}
I am trying to add the result to the last column, however what is happening is my loop is taking the result from the first row (which is a draw) and adding it to every entry in the last column. How can I get by this? any help would be greatly appreciated.
Thank you