使用 dplyr mutate & ifelse 替换值会产生奇怪的输出
Using dplyr mutate & ifelse to replace values produces strange output
我有一个数据框,WB。在 WB 上,我使用 dplyr 的 mutate() 和 ifelse() 将“..”值转换为相邻变量的值。
我得出的解决方案是,
mutate(WB, Rents2 = ifelse(Rents == "..", `X2014..YR2014.`, Rents)))
产生这个输出:
https://i.stack.imgur.com/7GFg5.png
为什么 Rents2 return 大值而不是 2014 年的可变数据?
原始数据由所有因素组成。数据提供者的字段是非数字的。解决方案是将数据转换为数字。
我有一个数据框,WB。在 WB 上,我使用 dplyr 的 mutate() 和 ifelse() 将“..”值转换为相邻变量的值。
我得出的解决方案是,
mutate(WB, Rents2 = ifelse(Rents == "..", `X2014..YR2014.`, Rents)))
产生这个输出: https://i.stack.imgur.com/7GFg5.png
为什么 Rents2 return 大值而不是 2014 年的可变数据?
原始数据由所有因素组成。数据提供者的字段是非数字的。解决方案是将数据转换为数字。