Nice alternative for some cases but I do not get the desires result as one long vector. I would change the last line to this:
unlist(as.vector(sapply(1:length(a), FUN=function(x, a, b) a[x]:b[x], a=a, b=b))) The indenting works better using a constant-width font, LOL. With all these twists, including using the base R methods like uppercase Map, the relative speed of these methods comes to mind. No doubt someone will suggest rewriting this as yet another C function for speed. -----Original Message----- From: R-help <r-help-boun...@r-project.org> On Behalf Of Izmirlian, Grant (NIH/NCI) [E] via R-help Sent: Monday, October 5, 2020 1:06 PM To: 'r-help@r-project.org' <r-help@r-project.org> Subject: Re: [R] R-help Digest, Vol 212, Issue 4 Hi -- there are lots of replies --I have not read them all, if someone else suggested this, sorry for duplication. This is similar to the suggestion using mapply, but not specific to matrices. In fact it's a kludge that applies to many settings. You 'sapply' over the index 1:2, and pass a, b as arguments: a <- c(1,4) b <- c(5,8) sapply(1:2, FUN=function(x, a, b)a[x]:b[x], a=a,b=b) -----Original Message----- From: r-help-requ...@r-project.org <r-help-requ...@r-project.org> Sent: Monday, October 05, 2020 6:04 AM To: r-help@r-project.org Subject: R-help Digest, Vol 212, Issue 4 Send R-help mailing list submissions to r-help@r-project.org To subscribe or unsubscribe via the World Wide Web, visit https://stat.ethz.ch/mailman/listinfo/r-help or, via email, send a message with subject or body 'help' to r-help-requ...@r-project.org You can reach the person managing the list at r-help-ow...@r-project.org When replying, please edit your Subject line so it is more specific than "Re: Contents of R-help digest..." ______________________________________________ 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 http://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 http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.