Skip to content
Back to formatted view

Raw Message

Message-ID: <OFB5F651EF.9202D095-ON852577F2.006D36D5-852577F2.006D4BD5@usgs.gov>
Date: 2010-12-07T19:53:33Z
From: Jonathan P Daily
Subject: More elegant magnitude method
In-Reply-To: <1201CF18-AC08-4FF0-B709-051D9B95489A@comcast.net>

What a brain fart...

Thanks!
--------------------------------------
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
"Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it."
     - Jubal Early, Firefly

David Winsemius <dwinsemius at comcast.net> wrote on 12/07/2010 02:50:34 PM:

> [image removed] 
> 
> Re: [R] More elegant magnitude method
> 
> David Winsemius 
> 
> to:
> 
> Jonathan P Daily
> 
> 12/07/2010 02:50 PM
> 
> Cc:
> 
> r-help
> 
> 
> On Dec 7, 2010, at 2:43 PM, Jonathan P Daily wrote:
> 
> > I have a need to find the order of number to get a scaling parameter 
> > as a
> > power of 10. I have a function that works *so far*, but it is ugly and
> > probably buggy. In the interest of avoiding code-based outliers in my
> > data, I thought I would ask if anyone here has a better way.
> >
> >> scl <- function(x){
> > + length(charToRaw(format(trunc(x), scientific = F)))-1}
> >> a <- 123456789
> >> b <- 1E15
> >> c <-  12.345
> >> scl(a)
> > [1] 8
> >> scl(b)
> > [1] 15
> >> scl(c)
> > [1] 1
> 
> scl<- function(x) trunc(log(x,10))
>  > scl(a)
> [1] 8
>  >
>  > scl(b)
> [1] 15
>  >
>  > scl(c)
> [1] 1
> 
> Seems mathematically clearer.
> -- 
> David Winsemius, MD
> West Hartford, CT
>