NA.rm | R Documentation |
Delete samples or variables with predefined number of NA
NA.rm(df, n = 0, direction = "rows")
df |
dataframe |
n |
maximum number of NA (if 0 –> all NAs) |
direction |
in which direction the deletion will take place ("rows" or "columns") |
dataframe after sorting and deleting NA
#' # 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.