samedi 8 octobre 2016

How to analyse each individual vector value in an if statement (R)

I'm trying to use an if statement to analyse the number of user-inputted values greater than or equal to 70. For every value they input greater than (or equal to) 70, I want the variable totalFirst to increase by 1. However, I am not sure how to make an if statement analyse each individual value in a vector.

Code so far:

totalFirst <- 0

prompt <- "What were your second year module results?(space separated)"
secondYearMark <- as.integer(strsplit(readline(prompt), " ")[[1]])
if (secondYearMark >= 70) totalFirst <- totalFirst + 1

Many thanks,

Jamie

Aucun commentaire:

Enregistrer un commentaire