R/delete_nodes_pa.R

Defines functions delete.nodes.pa

Documented in delete.nodes.pa

delete.nodes.pa <- function(G, pa, na.response = "none"){
  NAs <- which(is.na(pa))
  if(length(NAs) > 0 & na.response == "none"){ 
    warning("NAs in data need to be addressed. NAs converted 0.")
    pa <- unlist(ifelse(is.na(pa), 0, pa))}
  if(na.response == "treat.as.0") pa <- unlist(ifelse(is.na(pa), 0, pa))
  if(na.response == "treat.as.1") pa <- unlist(ifelse(is.na(pa), 1, pa)) 
  w <- which(pa == 0)
  nodes <- attributes(V(G))$names[w]
  d <- delete.vertices(G, nodes)
  if(length(NAs) > 0) d$NA.vertices <- attributes(V(G))$names[NAs]
  d
}

Try the streamDAG package in your browser

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

streamDAG documentation built on Oct. 7, 2023, 1:08 a.m.