[R] Scaling data

Jim Lemon jim at bitwrit.com.au
Mon Sep 28 12:30:18 CEST 2009


On 09/28/2009 07:55 PM, Dry, Jonathan R wrote:
> Hello all
>
> I have a data frame representing a matrix of data.  For each of my variables (rows) I want to scale the data between 0 (representing the minimum value in that row) and 1 (representing the maximum value in that row).  I was wondering if there is a simple function anywhere that does this?
>
>    
Hi Jonathan,
There are a number of such functions, but a particularly easy one in 
your case is rescale. Baptiste has already mentioned the one in ggplot, 
so I'll plug mine in plotrix:

mat1<-matrix(sample(1:20,16),nrow=4)
library(plotrix)
t(apply(mat1,1,rescale,c(0,1)))

Jim




More information about the R-help mailing list