# 11-1 For loops with data frames

# Load data file

results<-read.csv("SP11/CleanResults.csv", header=TRUE)

results

# Loop through dataframe using FOR returns the column vectors

for (i in results) print(i)

# Loop through dataframe rows using FOR

for (i in 1:nrow(results))
{
  print (i) # Print the loop variable
  print (results[i,]) # Print the row
}

# Change the value of results$Pass to reflect a pass mark of 50%

for (i in 1:nrow(results))
{
  ifelse(results[i,"Overall"]>=50, # IF condition
         results[i,"Pass"]<-TRUE,  # Perform if condition returns TRUE
         results[i,"Pass"]<-FALSE) # Perform if consition returns FALSE
}

results
