Replace all 0 values to NA

前端 未结 8 2489
庸人自扰
庸人自扰 2020-11-22 08:48

I have a dataframe with some numeric columns. Some row has a 0 value which should be considered as null in statistical analysis. What is the fastest way to replace all the 0

8条回答
  •  自闭症患者
    2020-11-22 09:17

    Let me assume that your data.frame is a mix of different datatypes and not all columns need to be modified.

    to modify only columns 12 to 18 (of the total 21), just do this

    df[, 12:18][df[, 12:18] == 0] <- NA
    

提交回复
热议问题