Re: [R] arbitrary scaling

2010-03-09 Thread Jim Lemon

On 03/09/2010 01:37 AM, Petr PIKAL wrote:

Hi all

I know I probably reinvented wheel but it was maybe simpler then search in
docs or ask help before I did my part.

I made a simple function which can scale a vector between chosen values.
Do anybody know simpler/better approach?
...
x- c(5,30,50)

myscale(x)
[1] 0.500 0.778 1.000


Hi Petr,
Try this:

library(plotrix)
rescale(x,c(0.5,1))

Jim

__
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] arbitrary scaling

2010-03-08 Thread Petr PIKAL
Hi all

I know I probably reinvented wheel but it was maybe simpler then search in 
docs or ask help before I did my part. 

I made a simple function which can scale a vector between chosen values. 
Do anybody know simpler/better approach?

myscale-function(x, miny=0.5, maxy=1) {
rx - diff(range(x, na.rm=T))
minx - min(x, na.rm=T)
tga - (maxy-miny)/rx
b - miny - tga* minx
res - x*tga+b
res
}

x - c(5,30,50)

myscale(x)
[1] 0.500 0.778 1.000

Thank you

Regards
Petr

__
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.


Re: [R] arbitrary scaling

2010-03-08 Thread Gabor Grothendieck
Perhaps approx:

   approx(range(x), c(0.5, 1), xout = x)$y

A one-linear, but longer, is also possible based on lm:

  predict(lm(c(0.5, 1) ~ x, data.frame(x = range(x))), data.frame(x))


On Mon, Mar 8, 2010 at 9:37 AM, Petr PIKAL petr.pi...@precheza.cz wrote:
 Hi all

 I know I probably reinvented wheel but it was maybe simpler then search in
 docs or ask help before I did my part.

 I made a simple function which can scale a vector between chosen values.
 Do anybody know simpler/better approach?

 myscale-function(x, miny=0.5, maxy=1) {
 rx - diff(range(x, na.rm=T))
 minx - min(x, na.rm=T)
 tga - (maxy-miny)/rx
 b - miny - tga* minx
 res - x*tga+b
 res
 }

 x - c(5,30,50)

 myscale(x)
 [1] 0.500 0.778 1.000

 Thank you

 Regards
 Petr

 __
 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.


Re: [R] arbitrary scaling

2010-03-08 Thread Petr PIKAL
Thanks

I would never deduct it out from the help page of approx.

Regards
Petr


r-help-boun...@r-project.org napsal dne 08.03.2010 15:47:37:

 Perhaps approx:
 
approx(range(x), c(0.5, 1), xout = x)$y
 
 A one-linear, but longer, is also possible based on lm:
 
   predict(lm(c(0.5, 1) ~ x, data.frame(x = range(x))), data.frame(x))
 
 
 On Mon, Mar 8, 2010 at 9:37 AM, Petr PIKAL petr.pi...@precheza.cz 
wrote:
  Hi all
 
  I know I probably reinvented wheel but it was maybe simpler then 
search in
  docs or ask help before I did my part.
 
  I made a simple function which can scale a vector between chosen 
values.
  Do anybody know simpler/better approach?
 
  myscale-function(x, miny=0.5, maxy=1) {
  rx - diff(range(x, na.rm=T))
  minx - min(x, na.rm=T)
  tga - (maxy-miny)/rx
  b - miny - tga* minx
  res - x*tga+b
  res
  }
 
  x - c(5,30,50)
 
  myscale(x)
  [1] 0.500 0.778 1.000
 
  Thank you
 
  Regards
  Petr
 
  __
  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.

__
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.