Skip to content

Instantly share code, notes, and snippets.

@pachevalier
Created January 24, 2014 14:39
Show Gist options
  • Select an option

  • Save pachevalier/8598521 to your computer and use it in GitHub Desktop.

Select an option

Save pachevalier/8598521 to your computer and use it in GitHub Desktop.
Cette fonction crée des catégories à partir d'une variable continue.
categorie <- function(x, breaks) {
c <- length(breaks)
temp <- 0
temp[x <= breaks[1]] <- 1
for (k in 1:c-1) {
temp[x > breaks[k] & x <= breaks[k+1]] <- k+1
}
temp[x > breaks[c]] <- c + 1
return(temp)
}
# Test
table(categorie(rnorm(100), breaks= c(-1,0,1)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment