[R] resclaing/resampling data
Jim Lemon
jim at bitwrit.com.au
Sat Oct 20 02:12:54 CEST 2007
Jim Lemon wrote:
> Jan M. Wiener wrote:
>
>>hello,
>>I am trying to rescale a matrix according to one column in the matrix.
>>Imagine having two matrices with 2 columns each:
>>
>>mat1:
>>1 2.1
>>2 2.2
>>3 2.2
>>4 2.4
>>5 2.7
>>6 2.9
>>
>>mat2:
>>1 1.9
>>2 2.0
>>3 2.1
>>4 2.2
>>5 2.4
>>6 3.0
>>7. 2.8
>>
>>I now want to rescale mat2 such that the values in columns 1 are also
>>between 1 and 6 (as in mat1). Of, course the values in column 2 should
>>be rescaled accordingly (simple interpolation).
>>Are there any predefined functions in R that does such rescaling?
>
>
> Hi Jan,
>
> library(plotrix)
> newmat1<-rescale(mat1,c(1,6))
> newmat2<-rescale(mat2,c(1,6))
>
Oops, didn't read that properly:
newmat2<-cbind(rescale(mat2[,1],c(1,6)),
rescale(mat2[,2],c(min(mat2[,2],max(mat2[,2])*6/7)))
and you can make it general by substituting:
max(mat1[,1])/max(mat2[,1]) for 6/7
Jim
More information about the R-help
mailing list