NA.rm: Delete samples or variables with predefined number of NA

View source: R/NA.rm.R

NA.rmR Documentation

Delete samples or variables with predefined number of NA

Description

Delete samples or variables with predefined number of NA

Usage

NA.rm(df, n = 0, direction = "rows")

Arguments

df

dataframe

n

maximum number of NA (if 0 –> all NAs)

direction

in which direction the deletion will take place ("rows" or "columns")

Value

dataframe after sorting and deleting NA

Examples

#' # Simulated data via rnorm function
df<-as.data.frame(matrix(rnorm(40*20, mean=0, sd=1),40,20))
set.seed(1234)
df<-as.data.frame(lapply(df, function(cc) cc[sample(c(TRUE, NA),
                                                  prob = c(0.85, 0.15),
                                                   size = length(cc),
                                                     replace = TRUE) ]))
df2 <- NA.rm(df, 8, direction="columns")
head(df[,1:5]) # before
head(df2[,1:5]) # after
# Variable V2 removed

AlexINSERM/Sci.ADS documentation built on March 24, 2024, 11:26 p.m.