[R] Classification by range

jim holtman jholtman at gmail.com
Thu Mar 8 21:53:24 CET 2012


?findInterval

> subjEnglish<-sample(-1:100,studentNumbers,replace=TRUE);
> grade <- c(-Inf, 39, 49, 59, 69, 79, 100)  # grade break points
> let <- c("U", "F", "D", "C", "B", "A", "A+")[findInterval(subjEnglish, grade)]
> cbind(subjEnglish, let)
      subjEnglish let
 [1,] "77"        "B"
 [2,] "93"        "A"
 [3,] "52"        "D"
 [4,] "19"        "U"
 [5,] "91"        "A"
 [6,] "99"        "A"
 [7,] "33"        "U"
 [8,] "83"        "A"
 [9,] "20"        "U"
[10,] "5"         "U"
>


On Thu, Mar 8, 2012 at 3:14 PM, Ajay Askoolum <aa2e72e at yahoo.co.uk> wrote:
> Given
>
> studentNumbers<-10;
>
> subjEnglish<-sample(-1:100,studentNumbers,replace=TRUE);
>
> when subEnglish <=0, 'U'
>                         <=39, 'F'
>                         <=49 'D'
>                         <=59, 'C'
>                         <=69, 'B'
>                         <=79,'A'
>                         <=100 'A+'
> I can solve this using a series of 'if' 'else' statements. I am looking for a simple expression that will give the letter classification for every element of subEnglish.
>
>
> Is there on?
>
> Thanks.
>
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.



More information about the R-help mailing list