My task is to write a function to check if, at most, a 1-stage drop per year is an appropriate assumption for my dataset. In other words, I want to return a logic indictor of FALSE if where the average drop in score is more than 1 per year and a logic indicator of TRUE when the average drop in score is 1 per year.
A sample of the data set is:
score <- matrix(c(8,rep(NA,6),7,NA,NA,3,NA,9,9,
6, 6, NA, NA,9,9,8,NA,NA,7,rep(NA,4),
rep(NA,9),8,NA,5,7,rep(NA,1),
rep(NA,8),7,3,rep(NA,4),
rep(NA,5),9,rep(NA,3),7,NA,NA,6,6),nrow=5,byrow=TRUE)
colnames(score) <- paste("Year",2003:2016,sep="")
rownames(score) <- 1:5
score
I'm quite at a loss on where to start, but here is my attempt before inserting into a function:
ifelse(score[score[i] - score[1+i,]=1], TRUE, FALSE)
Unsurprisingly, this gives an error message:
Error: unexpected '=' in "ifelse(score[score[i] - score[1+i,]="
Perhaps a for loop?
Aucun commentaire:
Enregistrer un commentaire