Hello,
I know that this is not what you want but cases like this are when
personal packages make life easier.
They don't have to be contributed packages, they are more of a
collection of personal habits.
span <- function(x, na.rm = FALSE) diff(range(x, na.rm = na.rm))
min, max, range and others default to na.rm = FALSE. Change at will.
Hope this helps,
Rui Barradas
Às 20:34 de 25/06/2025, Dennis Fisher escreveu:
you are missing the point:
span(…)
requires less typing than
diff(range(….))
just like
paste0
simplifies use of the paste command
Dennis Fisher MD
P < (The "P Less Than" Company)
Phone: 1-415-307-4791
www.PLessThan.com
On Jun 25, 2025, at 12:32 PM, Ebert,Timothy Aaron <teb...@ufl.edu> wrote:
I do not see the problem.
In base R
Min <- min(var, na.rm=T)
Max <- max(var, na.rm=T)
Span <- c(Min, Max)
Is the same output as
Span <- range(var, na.rm=T)
diff(range(var, na.rm=T)) returns Max - Min
range() returns a vector with two values, the minimum and the maximum.
What should the function "span" do that is not already done?
Tim
-----Original Message-----
From: R-help <r-help-boun...@r-project.org
<mailto:r-help-boun...@r-project.org>> On Behalf Of Dennis Fisher
Sent: Wednesday, June 25, 2025 2:11 PM
To: r-help <r-help@r-project.org <mailto:r-help@r-project.org>>
Subject: [R] Does this exist: diff(range(VAR, na.rm=T))
[External Email]
Version 4.4.2
OS X
Colleagues
I often need to determine the span of the x-variable in a graphic.
This is easy to determine with:
diff(range(VAR, na.rm=T))
I am not aware of any function in base R that accomplishes this and "span" is
not taken.
Would it be possible to add such a function? Not a major addition but often
useful.
Dennis
Dennis Fisher MD
P < (The "P Less Than" Company)
Phone: 1-415-307-4791
http://www.plessthan.com/
[[alternative HTML version deleted]]
______________________________________________
R-help@r-project.org <mailto:R-help@r-project.org> mailing list -- To
UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide https://www.r-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
--
Este e-mail foi analisado pelo software antivírus AVG para verificar a presença
de vírus.
www.avg.com
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.