#'@title NA_inspect
#'@description This function inspects your datasets (stored int a list)
#' in order to evaluate if your data contains na values.
#'@param dat list with your datasets. It can be the same list generated by ReadData function.
#'@export NA_inspect
#'@return List with missing values information or message if your data doesn't have missing
#'@author Laura M Zingatetti
#'
#' @examples
#' {
#'data('Ruminotypes')
#'Data<-Ruminotypes$`16_S`
#'#13 indicates the number of columns with missing values.
#'Columns<-sample(1:ncol(Data),13)
#'for (i in Columns){
#'n<-sample(1:30,1)
#'Data[sample(1:nrow(Data),n),i]<-NA
#'}
#'
#'Data_1<-list("16_S"=Ruminotypes$`16_S`,"16_S_NA"=Data)
#'NA_inspect(Data_1)
#' }
#'
#' @name NA_inspect
#' @rdname NA_inspect
NA_inspect<-function (dat){
if(!is.list(dat)){
stop("check data into a list")
}
wherenans<-function(x) sapply(x, function(y) which(is.na(y)))
dat2<-lapply(dat,wherenans)
counts<-lapply(dat2,function(m){sapply(m ,function(x) length(x))})
dataswithna<-lapply(counts,function(x) unique(x))
tableswithna<-lapply(dataswithna, function(x) isTRUE(any(x!=0)))
if(any((unlist(tableswithna)))){
index<- which((unlist(tableswithna)))
datosnas<-lapply(index,function(x) dat[[x]])
indices_<-lapply(index,function(x) dat2[[x]])
porc_<-lapply(index,function(x) counts[[x]]/dim(dat[[x]])[1])
tot_<-lapply(index,function(x) sum(counts[[x]])/(dim(dat[[x]])[1]*dim(dat[[x]])[2]))
totales<-lapply(index,function(x) sum(counts[[x]]))
message(cat("you have nans in the next datasets:" , names(datosnas)))
return(list("Nans_by_col_perc"=porc_, "Total_nans_perc"=tot_,"Num_nas"=totales))
}
else{
message("there are no missing values in your data ")
return(message("you can continue with further analysis"))
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.