将空值替换为0或任何值
对于数据集测试,我们将列SalesQty null
值替换为0
数据集:测试
+---+----+--------+-------------+-------+--------+-----------+
|mon|year|mon_year|location_code|item_no|SalesQty|mmon_year_1|
+---+----+--------+-------------+-------+--------+-----------+
| 11|2012| 112012| null| null| null| null|
| 11|2012| 112012| null| null| null| null|
| 11|2012| 112012| null| null| null| null|
+---+----+--------+-------------+-------+--------+-----------+
test$SalesQty <- when(isNull(test$SalesQty), 0 )
生成的数据集结果:
+---+----+--------+-------------+-------+--------+-----------+
|mon|year|mon_year|location_code|item_no|SalesQty|mmon_year_1|
+---+----+--------+-------------+-------+--------+-----------+
| 11|2012| 112012| null| null| 0 | null|
| 11|2012| 112012| null| null| 0 | null|
| 11|2012| 112012| null| null| 0 | null|
+---+----+--------+-------------+-------+--------+-----------+
答案 0 :(得分:2)
“null”是字符串。
test$SalesQty <- ifelse(test$SalesQty == "null", 0, test$SalesQty)