[R] OK, next Q - a sort of factorial on a vector

Uwe Ligges ||gge@ @end|ng |rom @t@t|@t|k@tu-dortmund@de
Tue Jun 20 19:45:38 CEST 2023


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, 6,8,10, 12,15, 20)
> 
> and this:
> 
>    !(1,2,NA,4,5)
> 
> would give this:
> 
>    (2,4,5, 8,10, 20)
> 
> ?
> 
> Thanks!
> 
> Phil.



More information about the R-help mailing list