#' @title NA to something
#' @description convert NA to something
#' @param s The input vector (of arbitrary class)
#' @param x The elements to transform into NA resp. what to transform NA into
#' @return A vector with same dimension and class as s
#'
#' @examples na_na2x(na_x2na(c(1:10),5),5)
#'
#' @rdname na_na2x
#' @export
na_na2x <- function (s, x = 0)
{
sapply(s, function(y) ifelse(is.na(y), x, y))
}
#' @title na_x2na
#' @description convert vecter to NA
#' @param s The input vector (of arbitrary class)
#' @param x The elements to transform into NA resp. what to transform NA into
#' @return A vector with same dimension and class as s
#'
#' @examples na_x2na(1:10, 1:5)
#'
#' @rdname na_x2na
#' @export
na_x2na <- function (s, x = 0)
{
sapply(s, function(y)
ifelse(y %in% x, NA, y))
}
#' @title NULL to NA
#' @description try to convert NULL to NA
#' @param x list element
#'
#' @return list element
#' @rdname null2na
#' @export
#' @examples
#' test <- list(1, 2, 3, NULL)
#' test %>% map(~ na_null2na(.x))
#'
na_null2na <- function (x)
{
if (is.null(x) || length(x) == 0)
x <- as.character(NA)
else x <- unique(unlist(x))
x
}
# RpsiXML::null2na
#' @title plot the missing value
#' @description plot the missing value
#' @param df dataframe
#'
#' @return plot
#'
#' @examples
#'
#' @importFrom naniar vis_miss
#'
#' @rdname na_vis_miss
#' @export
#'
na_vis_miss <-
function(df) {
naniar::vis_miss(df)
}
#' @title remove vector NA element
#' @description remove vector NA element
#' @param x vector
#'
#' @return vector
#'
#' @examples
#'
#'
#' @rdname na_remove
#' @export
na_remove <- function(x){
x <-x[which(!is.na(x))]
return(x)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.