[R] Scaling values 0-255 -> -1 , 1 - how can this be done?

Marc Schwartz marc_schwartz at me.com
Wed Nov 21 18:11:34 CET 2012


On Nov 21, 2012, at 9:32 AM, Brian Feeny <bfeeny at me.com> wrote:

> 
> I have a dataframe in which I have values 0-255, I wish to transpose them such that:
> 
> if value  > 127.5 value = 1
> if value < 127.5 value = -1
> 
> I did something similar using the "binarize" function of the biclust package, this transforms my dataframe to 0 and 1 values, but I wish
> to use -1 and 1 and looking for a way in R to do this.
> 
> Brian

See ?ifelse

  ifelse(value > 127.5, 1, -1)

You might want to think about what happens when value == 127.5 ...

Regards,

Marc Schwartz




More information about the R-help mailing list