Skip to content
Back to formatted view

Raw Message

Message-ID: <alpine.DEB.2.00.1012071149510.25195@springer.Berkeley.EDU>
Date: 2010-12-07T19:54:09Z
From: Phil Spector
Subject: More elegant magnitude method
In-Reply-To: <OFF855C504.FE8D235C-ON852577F2.006C45AA-852577F2.006C61F1@usgs.gov>

Jonathan -
    If I understand correctly,

      max(0,floor(log(x,10)))

will return the value you want.

 					- Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu


On Tue, 7 Dec 2010, 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
>
> 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
>
> ______________________________________________
> R-help at 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.
>