How to remove rows with inf from a dataframe in R

后端 未结 6 651
自闭症患者
自闭症患者 2020-12-29 03:50

I have a very large dataframe(df) with approximately 35-45 columns(variables) and rows greater than 300. Some of the rows contains NA,NaN,Inf,-Inf values in

6条回答
  •  渐次进展
    2020-12-29 04:09

    To remove the rows with +/-Inf I'd suggest the following:

    df <- df[!is.infinite(rowSums(df)),]
    

    or, equivalently,

    df <- df[is.finite(rowSums(df)),]
    

    The second option (the one with is.finite() and without the negation) removes also rows containing NA values in case that this has not already been done.

提交回复
热议问题