R/gr_intersect.R

Defines functions intersect.list intersect.default intersect

# It finds the intersection of all objects in a list.
# x a list
intersect<- function(x)
{
  UseMethod("intersect", x)
}

#' @export
intersect.default<- function(x)
{
  return(base::intersect(x))
}




#' @export
intersect.list<- function(x)
{  if (length(x)==1)
   {
     x<- unlist(x)
     names(x)<- c()
     return(x)
   } else {
            g<- x[[1]]
            for (i in 2:length(x))
            {
               g<- base::intersect(g, x[[i]])
            }
            return(g)
          }
}

Try the gremes package in your browser

Any scripts or data that you put into this service are public.

gremes documentation built on Feb. 16, 2023, 8:06 p.m.