[R] More elegant magnitude method
Ravi Varadhan
rvaradhan at jhmi.edu
Tue Dec 7 20:55:14 CET 2010
I would prefer:
round(log10(x))
Ravi.
-------------------------------------------------------
Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology School of Medicine Johns
Hopkins University
Ph. (410) 502-2619
email: rvaradhan at jhmi.edu
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of David L Lorenz
Sent: Tuesday, December 07, 2010 2:53 PM
To: Jonathan P Daily
Cc: r-help at r-project.org; r-help-bounces at r-project.org
Subject: Re: [R] More elegant magnitude method
Jonathan,
I'd just return the integer part of the common log:
floor(log10(x))
Dave
From:
Jonathan P Daily <jdaily at usgs.gov>
To:
r-help at r-project.org
Date:
12/07/2010 01:44 PM
Subject:
[R] More elegant magnitude method
Sent by:
r-help-bounces at r-project.org
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.
[[alternative HTML version deleted]]
______________________________________________
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.
More information about the R-help
mailing list