HI, You could also use: set.seed(5) x1<-data.frame(matrix(sample(0:255,80,replace=TRUE),ncol=10)) library(car) do.call(cbind,lapply(x1,function(x) x<-recode(x,"0:127.5=-1;127.6:255=1"))) # X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 #[1,] -1 1 -1 -1 -1 1 1 -1 1 -1 #[2,] 1 -1 1 -1 -1 -1 1 -1 1 1 #[3,] 1 -1 1 -1 -1 1 -1 -1 1 -1 #[4,] -1 -1 1 1 -1 1 1 -1 -1 1 #[5,] -1 -1 1 -1 1 1 1 1 1 -1 #[6,] 1 1 1 1 1 1 1 -1 1 1 #[7,] 1 -1 -1 -1 -1 1 1 1 1 -1 #[8,] 1 -1 -1 -1 -1 -1 -1 1 1 -1 A.K.
----- Original Message ----- From: Brian Feeny <bfe...@me.com> To: r-help@r-project.org Cc: Sent: Wednesday, November 21, 2012 10:32 AM Subject: [R] Scaling values 0-255 -> -1 , 1 - how can this be done? 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 ______________________________________________ R-help@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. ______________________________________________ R-help@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.