Created
January 24, 2014 14:39
-
-
Save pachevalier/8598521 to your computer and use it in GitHub Desktop.
Cette fonction crée des catégories à partir d'une variable continue.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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