Skip to content

Instantly share code, notes, and snippets.

@abikoushi
Created January 24, 2015 16:36
Show Gist options
  • Select an option

  • Save abikoushi/d3a8ce487bfada72fe30 to your computer and use it in GitHub Desktop.

Select an option

Save abikoushi/d3a8ce487bfada72fe30 to your computer and use it in GitHub Desktop.
punc <- function(x){
len = length(x)
pp <- which(x > 1.5*IQR(x) + quantile(x,3/4))
pplen <- length(pp)
group <- rep(1,len)
group[pp] <- 1
if(pplen==0){
return(group)
break
}
if(pplen==1){
group[pp] <- 2
group[(pp+1):len] <- 3
return(group)
break
}
for(i in 1:(pplen-1)){
group[pp[i]] <- i + 1
if(pp[i+1]- pp[i] !=1){
group[(pp[i]+1):(pp[i+1]-1)] <- i+2
}
}
group[pp[pplen]] <- i+3
group[(pp[pplen]+1):(len)] <- i+4
return(as.numeric(as.factor(group)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment