lundi 15 novembre 2021

statement to skip empty data frames in a function

I have a function similar to this in R, which uses a df as main argument. However, the df could be empty and I would like to skip those if I run the function using lapply e.g lapply(FileNames, function(y) my.function(y))

my function looks like this

my.function <- function(table) {
file <- read.csv(table, header=T)

  if(nrow(table) == 0) 
   {next}

#skip the df if is empty and stop processing that df
#do more stuffs if not empty
}

I've tried this so far but if the data frame is empty the whole process crashes, any tip?

Aucun commentaire:

Enregistrer un commentaire