[datatable-help] R - Comparison
Nicolas Paris
niparisco at gmail.com
Wed Nov 4 15:53:52 CET 2015
hello,
use ifelse that is vectorial function
x <- c( 0, 2, 5, 4, 1, 9 )
y <- ifelse(x<=3,"F",ifelse( 3 < x && x <= 6,"M",ifelse(6<x,"E","ERROR")))
2015-11-04 11:01 GMT+01:00 Ash111 <hamza_essid at hotmail.fr>:
> Hello everyone,
>
> I have a vector X = [ 0 2 5 4 1 9 ]
> I want to build another vector Y wich will have the same length as X and
> which contains the comparison of the elements of x as follows :
> if x < = 3: returns F
> if 3 < x < = 6: returns M
> if 6 < x: returns E
>
> I expected the result:
> Y = [F F M M F E ]
>
> How to do that with R ??
>
> Thank you :-)
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/R-Comparison-tp4714329.html
> Sent from the datatable-help mailing list archive at Nabble.com.
> _______________________________________________
> datatable-help mailing list
> datatable-help at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
More information about the datatable-help
mailing list