Eric,
On 2023-06-21 04:02, Eric Berger wrote:
Hi Philip,
In the decades since you learned R there have been some additions to
the language.
In particular, R now supports lambda functions.
Applying this feature to Ivan's beautiful solution cuts down 7
characters (continuing his golfing analogy)
Hi Philip,
In the decades since you learned R there have been some additions to the
language.
In particular, R now supports lambda functions.
Applying this feature to Ivan's beautiful solution cuts down 7 characters
(continuing his golfing analogy)
unlist(lapply(seq_along(x), \(i) x[i] * x[-(1:i)]
Ivan,
On 2023-06-21 03:32, Ivan Krylov wrote:
В Wed, 21 Jun 2023 03:13:52 +1000
Philip Rhoades via R-help пишет:
This:
!(1,2,3,4,5)
would give this:
(2,3,4,5, 6,8,10, 12,15, 20)
Do you mean taking a product of every element of the vector with all
following vector elements? A relat
vf <- function(x){
o <- outer(x, x)
as.vector(na.omit(o[lower.tri(o)]))
}
vf(1:5)
vf(c(1,2,NA,4,5))
Best,
Uwe Ligges
On 20.06.2023 19:13, Philip Rhoades via R-help wrote:
People,
What I mean is, is there an elegant way to do this:
This:
!(1,2,3,4,5)
would give this:
(2,3,4,5,
Well, I think this is reasonable elegant, but ymmv. Turning it into a
function and removing NA values is left for you.
> x <- 1:5
> unlist(sapply(seq(1, length(x) - 1), function(i){x[i] * x[seq(i + 1,
> length(x))]}))
[1] 2 3 4 5 6 8 10 12 15 20
>
> x <- c(1, 2, NA, 4, 5)
> unlist(sapply(s
В Wed, 21 Jun 2023 03:13:52 +1000
Philip Rhoades via R-help пишет:
> This:
>
>!(1,2,3,4,5)
>
> would give this:
>
>(2,3,4,5, 6,8,10, 12,15, 20)
Do you mean taking a product of every element of the vector with all
following vector elements? A relatively straightforward way would be
(gi
6 matches
Mail list logo