I'm using a command to return the points at which participants reach 8 contiguous responses in a row. The command is:
test <- which( rle(goo)$values==1 & rle(goo)$lengths >= 8)
where:
goo <- c(1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0)
if the participant never achieves 8 contiguous responses i'd like to set the variable "test" to equal -1. As it stands, the command returns integer(0) when 8 contiguous responses in a row are not found. I've tried writing an if command but can't seem to get it right.
Thanks in advance,
Will
If test is integer(0) then its length is 0. You can also coerce it to logical with !
length(test)
0
!(length(test)
TRUE # and would be FALSE for any vector with normal length
> !(length( c(1,2,3) ))
[1] FALSE
So:
> if ( !length(test) ) {test<- -1}
> test
[1] -1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With