Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RTbins <- function(x) {
- # Don't vincentize if too few cells
- if (length(x)<10) {
- binsRT = c(NA, NA, NA, NA, NA, NA)
- return(binsRT)
- }
- # Find the percentiles of the array; these are your bounds
- counti=0
- critpe <- c()
- for(p in seq(0, 1, by=0.2)) {
- counti = counti + 1
- critpe <- c(critpe, quantile(x, p))
- }
- RTb = vector('list', 5)
- # Now sort into bins (fastest to slowest)
- for(i in 1:length(x)) {
- ifelse( (x[i] >= critpe[1] & x[i] < critpe[2] ) , RTb[1] <- c(RTb[1],x[i]),
- ifelse( (x[i] >= critpe[2] & x[i] < critpe[3] ), RTb[2] <- c(RTb[2],x[i]),
- ifelse( (x[i] >= critpe[3] & x[i] < critpe[4] ), RTb[3] <- c(RTb[3],x[i]),
- ifelse( (x[i] >= critpe[4] & x[i] < critpe[5] ), RTb[4] <- c(RTb[4],x[i]),
- ifelse( (x[i] >= critpe[5] & x[i] < critpe[6] ), RTb[5] <- c(RTb[5],x[i]), next
- )))))
- }
- binsRT <- c(mean(x, na.rm=TRUE))
- binsRT <- c(binsRT, mean(RTb[1]))
- binsRT <- c(binsRT, mean(RTb[2]))
- binsRT <- c(binsRT, mean(RTb[3]))
- binsRT <- c(binsRT, mean(RTb[4]))
- binsRT <- c(binsRT, mean(RTb[5]))
- return(binsRT)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement