Advertisement
Guest User

VincentizeRTs

a guest
Sep 11th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.36 KB | None | 0 0
  1. RTbins <- function(x) {
  2.   # Don't vincentize if too few cells
  3.   if (length(x)<10) {
  4.     binsRT = c(NA, NA, NA, NA, NA, NA)
  5.     return(binsRT)
  6.   }
  7.  
  8.   # Find the percentiles of the array; these are your bounds
  9.   counti=0
  10.   critpe <- c()
  11.   for(p in seq(0, 1, by=0.2)) {
  12.     counti = counti + 1
  13.     critpe <- c(critpe, quantile(x, p))
  14.   }
  15.  
  16.   RTb = vector('list', 5)
  17.  
  18.   # Now sort into bins (fastest to slowest)
  19.   for(i in 1:length(x)) {
  20.     ifelse( (x[i] >= critpe[1] & x[i] < critpe[2] ) , RTb[1] <- c(RTb[1],x[i]),
  21.            
  22.            ifelse( (x[i] >= critpe[2] & x[i] < critpe[3] ), RTb[2] <- c(RTb[2],x[i]),
  23.                    
  24.                   ifelse( (x[i] >= critpe[3] & x[i] < critpe[4] ), RTb[3] <- c(RTb[3],x[i]),
  25.                          
  26.                          ifelse( (x[i] >= critpe[4] & x[i] < critpe[5] ), RTb[4] <- c(RTb[4],x[i]),
  27.                                  
  28.                                  ifelse( (x[i] >= critpe[5] & x[i] < critpe[6] ), RTb[5] <- c(RTb[5],x[i]), next
  29.                                                                                              
  30.     )))))
  31.   }
  32.  
  33.   binsRT <- c(mean(x, na.rm=TRUE))
  34.   binsRT <- c(binsRT, mean(RTb[1]))
  35.   binsRT <- c(binsRT, mean(RTb[2]))
  36.   binsRT <- c(binsRT, mean(RTb[3]))
  37.   binsRT <- c(binsRT, mean(RTb[4]))
  38.   binsRT <- c(binsRT, mean(RTb[5]))
  39.  
  40.  
  41.   return(binsRT)
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement