Why does an empty dataframe fail an is.null() test?

后端 未结 3 1178
清歌不尽
清歌不尽 2021-02-02 10:00

please excuse me if my question is quite basic. I created an empty data frame by df <- data.frame() and obviously the data frame is NULL (empty). when I try to

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-02 10:37

    Above answers are correct, is.na and is.null couldn't not detect empty value in R. This is what I would do to calculate how many empty value you have in your data frame 'df' in this case.

    is.na(df[df =='']) <- TRUE # this just replace NA to the empty value in df.

    sum(is.na(df)) # would give you an idea how many empty values you have in your 'df'.

    Hope this is helpful.

提交回复
热议问题