0

I'm trying to find a way to identify monotone answer patterns of participants in my experiment. For example if someone answered the first Option, coded as "1" in all of the first 10 Questions. I tried to do it with the standard deviation which has to be zero if there is no variance in the answers, but i wasn't successful so far. Here is my attempt:

m.check <- function(data,startrow, endrow){
   out <- ifelse(sapply(data, startrow:endrow,sd) ==0,T, F)
   return(out)
}
data$mono <- m.check(as.numeric(data,1,10))
MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • Perhaps something like this? It checks to see if any runs are the same length as the vector itself and will return `TRUE` if it is. `monotone <- function(x)any(rle(x)$lengths == length(x))`. – Dan Sep 24 '19 at 14:48
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Sep 24 '19 at 15:02
  • an alternative approach could be `all(x == x[1])` in the function – Ben Sep 24 '19 at 18:16

0 Answers0