And some more from 2013:
https://stackoverflow.com/questions/14868406/collapse-continuous-integer-runs-to-strings-of-ranges
Can be as short as:
condense <- function(x)
unname(tapply(x, c(0, cumsum(diff(x) != 1)), FUN = function(y)
paste(unique(range(y)), collapse = "-")
))
z <- c(1
There are some answers from 2016 here:
https://stackoverflow.com/questions/34636461/collapse-consecutive-runs-of-numbers-to-a-string-of-ranges
On 2025-02-21 7:59 p.m., Steven Ellis wrote:
Hi Dennis,
A quick Claude request:
"using r I have a sequence like:1, 3, 4, 5, 7, 8, 12, 13, 14
Dennis,
You are supposedly using a vector containing integers, in order, and want to
find sequences to rewrite compactly based on your example.
What result do you want. An integer vector cannot hold something like 3-5 so
do you want an integer of character stringls like this:
c("1", "3-5", "7-8"
Hi Dennis,
A quick Claude request:
"using r I have a sequence like:1, 3, 4, 5, 7, 8, 12, 13, 14, 15,
20I would like to display it as:1, 3-5, 7-8, 12-15, 20"
yielded:
condense_sequence <- function(nums) {
if (length(nums) == 0) return("")
if (length(nums) == 1) return(as.char
Cute exercise!
"Simple" is in the eyes of the beholder, of course. There is probably a
package out there that can do this in a trice .
But my first thought -- so caveat emptor!, as my thoughts, first or last,
are often not so, um... thoughtful -- is to diff() the sequence (as
numerics) -- so that
R 4.4.0
OS X
Colleagues
I have a sequence like:
1, 3, 4, 5, 7, 8, 12, 13, 14, 15, 20
I would like to display it as:
1, 3-5, 7-8, 12-15, 20
Any simple ways to accomplish this?
Dennis
Dennis Fisher MD
P < (The "P Less Than" Company)
Phone / Fax: 1-866-PLessThan (1-866-753-7784)
It sounds like your first course of action should be to contact the package
maintainer. See ?maintainer or consult the Description file for the package
for their email.
Cheers,
Bert
"An educated person is one who can entertain new ideas, entertain others,
and entertain herself."
On Fri, Feb 21
More specifically, there is an issues list for the package here:
https://github.com/nk027/bvar/issues (I got there by looking at the
BugReports: field in the package description at
https://CRAN.R-project.org/package=BVAR )
cheers
Ben Bolker
On 2/21/25 11:07, Bert Gunter wrote:
It sou
Hi,
I am working on a modelling project for Brazilian inflation, for which I am
tempted to use the BVAR package in R. I read the paper and the documentation
and yet I could not find any further information on how the values of the
hyperparameters of the Minnesota prior (bv_lambda, bv_alpha, bv_
Ivan Krylov wrote:
>> text(1, 11, "baseline\255defined")
>> text(1, 9, "done")
>> graphics.off()
>>
>> They like that dash - but I never knew what it was called.
>>
>> Recently work updated my PC to the latest version of Windows, and,
>> perforce, I updated to the latest version of R (4.4.
10 matches
Mail list logo