3

I have a variable named Esteem that is in a scale 1:7. I would like to rescale it to 1:100. I understand that the R program scales can do so, however I am having problems with the syntax.

Could someone provide an example of how can I rescale that variable? Also, is there a tool that I can use in R Commander to do that?

Thanks very much!

Ramon
  • 31
  • 1
  • 3
  • What did you try so far? – Jaap Sep 22 '14 at 17:39
  • Thanks for all the great responses. I have tried the seq tool. It looks like it provides the same results as the rescale function, isn't? Also, is there a way I do this transformation directly in the dataset (i.e. that it creates a column with the new scaled variable)? Finally, if my data has decimals, do I need to add a rounding function as well to the function? Thanks again!!! – Ramon Sep 23 '14 at 12:06

2 Answers2

5

I don't know RCommander. There is a package called RPMG that has a rescaling function, which is generally used for graphic purposes. I'm not sure it's entirely doing what you want (as you haven't provided an example including example output).

But, this may be relevant.

set.seed(1)
x<-sample(1:7, 10, replace=T)
x
#[1] 2 3 5 7 2 7 7 5 5 1

library(RPMG)
RESCALE(x, 1, 100, 1, 7)
#[1]  17.5  34.0  67.0 100.0  17.5 100.0 100.0  67.0  67.0   1.0

Within RESCALE the arguments after x are: the new.min, new.max, old.min, old.max of a scale.

This function is actually very simple:

RESCALE <- function (x, nx1, nx2, minx, maxx) 
{ nx = nx1 + (nx2 - nx1) * (x - minx)/(maxx - minx)
  return(nx)
}
jalapic
  • 13,792
  • 8
  • 57
  • 87
3

You can do something like that using base R too (using @jalapics data)

seq(1, 100, length.out = 7)[x]
## [1]  17.5  34.0  67.0 100.0  17.5 100.0 100.0  67.0  67.0   1.0
David Arenburg
  • 91,361
  • 17
  • 137
  • 196