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 www.PLessThan.com [[alternative HTML version deleted]]
Not speaking for R-core, but the general answer to "could we include this simple helper function in base R?" is "no, put it in a package or in your own set of source()d helper functions; if it turns out to be incredibly useful we might add it somewhere down the line". You could ask to have it added to the `gtools` package, which has been around for a while and has no strong dependencies ... https://github.com/r-gregmisc/gtools/issues On 2025-06-25 2:11 p.m., Dennis Fisher wrote:> 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 > www.PLessThan.com > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.-- Dr. Benjamin Bolker Professor, Mathematics & Statistics and Biology, McMaster University Director, School of Computational Science and Engineering > E-mail is sent at my convenience; I don't expect replies outside of working hours.
On 2025-06-25 2:11 p.m., Dennis Fisher wrote:> 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.Then you should write one that suits your needs. It could have just the line above, or you could make it fancier, expanding the range a bit like plot() does.> > Would it be possible to add such a function? Not a major addition but often useful.If you think others would like to use it, then include it in a package and publish the package. Duncan Murdoch
Duncan That would certainly be a possibility but it seems to me that this is sufficiently simple to add to base R. If it is in a package, users would need to install the package. Dennis Dennis Fisher MD P < (The "P Less Than" Company) Phone: 1-415-307-4791 www.PLessThan.com> On Jun 25, 2025, at 11:11?AM, Dennis Fisher <fisher at plessthan.com> wrote: > > 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 > www.PLessThan.com >[[alternative HTML version deleted]]
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-bounces at r-project.org> On Behalf Of Dennis Fisher Sent: Wednesday, June 25, 2025 2:11 PM To: r-help <r-help at 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 at 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.
We can define span(x) another way: span(x) = max {|a-b| | a \in x, b \in x} This gives the same result as diff(range(x)) for logical x, integer x, and double x, but it also works for complex x and in general for any collection of elements of something that could be seen as a normed vector spans. This makes a good example of why it might be a bad idea to jump prematurely to a definition in base R. But there is another and more obviously statistical reason. Consider a time series. diff(range(..)) makes sense on a (real, complex, multivariate) time series, but the span of a time series is more usually thought of as the span of *time* it is measured over. On Thu, 26 Jun 2025 at 06:11, Dennis Fisher <fisher at plessthan.com> wrote:> > 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 > www.PLessThan.com > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.