I am a beginner at R and searched the forums and did not find an answer to this question. I am trying to create a loop in R that counts whether a condition is met between 2 rows in a dataframe. I understand that this is not an efficient way to do this but it is for a class assignment. My problem is that my code is creating an endless loop rather giving me the counter output and it is unclear to me how to fix it. I would greatly appreciate any suggestion. The code is below:
counter=0
for (i in 1:nrow(dataframe))
{if (dataframe$column1[i]>dataframe$column2[i]==TRUE)
{
counter=counter+1}
}
print(counter)