I have a data frame with 102 rows, and I need to develop a for loop with an if statement to populate a new column "Season" based on other columns (Sp, Su, Fa, Wi). I have a "1" populating the season that the sample took place (see below).
Sp Su Fa Wi
1 0 0 0
0 0 0 1
I tried just doing summer, in a loop, but I get tons of errors. I just can't seem to grasp For and if loops. ANy help would be appreciated.
for(i in 1:102) { if(myData$Su==1) myData$Season=Summer}
Error:
In if (myData$Su == 1) myData$Season = Summer :
the condition has length > 1 and only the first element will be used