Richard, your definition is, of course, not valid R code. I assume the pseudocode is easier to write in a language like python and says that you want to loop through all items and compare each item to every other item in a second similar loop (meaning it happens twice and also compares items to themselves) and take the absolute values of subtracting one from the other and keep the maximum.
If I am right, this is a bit of overkill for the purpose as it generate O(N^2) results that are then evaluated for a maximum. The more straightforward methods are O(N) as they find the smallest and largest (perhaps in one sweep) and do a subtraction. Admittedly, if you want a very general solution that includes complex numbers or quaternions or octonions, it may be needed. But I suspect that for most common purposes, it won't be worth the effort. And, in any case, I am not sure how robust the min() function works for some of these cases. -----Original Message----- From: R-help <r-help-boun...@r-project.org> On Behalf Of Richard O'Keefe Sent: Thursday, June 26, 2025 3:50 AM To: Dennis Fisher <fis...@plessthan.com> Cc: r-help <r-help@r-project.org> Subject: Re: [R] Does this exist: diff(range(VAR, na.rm=T)) 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 <fis...@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@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. ______________________________________________ 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. ______________________________________________ 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.