% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/network-utils.R
\name{filter_nodes}
\alias{filter_nodes}
\alias{subset_nodes}
\title{Filter Nodes by Metadata or Centrality}
\usage{
filter_nodes(
  x,
  ...,
  .keep_edges = c("internal", "none"),
  keep_format = FALSE,
  directed = NULL
)

subset_nodes(
  x,
  ...,
  .keep_edges = c("internal", "none"),
  keep_format = FALSE,
  directed = NULL
)
}
\arguments{
\item{x}{Network input: cograph_network, matrix, igraph, network, or tna object.}

\item{...}{Filter expressions using any node column or centrality measure.
Available variables include:
\describe{
\item{Node columns}{All columns in the nodes dataframe: \code{id}, \code{label},
\code{name}, \code{x}, \code{y}, \code{inits}, \code{color}, plus any custom}
\item{Centrality measures}{\code{degree}, \code{indegree}, \code{outdegree},
\code{strength}, \code{instrength}, \code{outstrength}, \code{betweenness},
\code{closeness}, \code{eigenvector}, \code{pagerank}, \code{hub}, \code{authority}}
}
Examples: \code{degree >= 3}, \code{label \%in\% c("A", "B")},
\code{pagerank > 0.1 & degree >= 2}.}

\item{.keep_edges}{How to handle edges. One of:
\describe{
\item{\code{"internal"}}{(default) Keep only edges between remaining nodes}
\item{\code{"none"}}{Remove all edges}
}}

\item{keep_format}{Logical. If TRUE, matrix, igraph, and statnet network
inputs are returned in that format. Default FALSE
returns cograph_network (universal format).}

\item{directed}{Logical or NULL. If NULL (default), auto-detect from matrix
symmetry. Set TRUE to force directed, FALSE to force undirected.
Only used for non-cograph_network inputs.}
}
\value{
A cograph_network object with filtered nodes. If \code{keep_format = TRUE},
matrix, igraph, and statnet network inputs are converted back to that type.
}
\description{
Filter nodes using dplyr-style expressions on any node column or centrality
measure. Returns a cograph_network object by default (universal format), or
optionally a matrix, igraph, or statnet network object when
\code{keep_format = TRUE} and the input used one of those formats.
}
\examples{
adj <- matrix(c(0, .5, .8, 0, .5, 0, .3, .6,
                .8, .3, 0, .4, 0, .6, .4, 0), 4, 4, byrow = TRUE)
rownames(adj) <- colnames(adj) <- c("A", "B", "C", "D")

# Keep only high-degree nodes
filter_nodes(adj, degree >= 3)

# Filter by label, combined with degree
filter_nodes(adj, degree >= 2 & label != "D")
}
\seealso{
\code{\link{filter_edges}}, \code{\link{splot}}, \code{\link{subset_nodes}}
}
