Home > Software design >  Write an if statment if the data frame equals "A tibble: 0 × 0"
Write an if statment if the data frame equals "A tibble: 0 × 0"

Time:09-04

I want to write an if statment which prints something if a certain value is found. For example, the data looks like:

$`https://www.fotocasa.es/es/comprar/viviendas/ain/todas-las-zonas/l/1?sortType=publicationDate`
# A tibble: 0 × 0

I want to write something along the lines of:

if(df == "A tibble: 0 × 0"){
   print("An empty dataframe")
} else{
   print("Not an empty dataframe")
}

Data

data = list(`https://www.fotocasa.es/es/comprar/viviendas/ain/todas-las-zonas/l/1?sortType=publicationDate` = structure(list(), class = c("tbl_df", 
"tbl", "data.frame"), row.names = integer(0), .Names = character(0)))

CodePudding user response:

Perhaps, we can create a condition with is.null

if(nrow(data[[1]])==0) {
    print("An empty dataframe")
  } else {
    print("Not an empty dataframe")
}
[1] "An empty dataframe"
  •  Tags:  
  • r
  • Related