不确定为什么会这样。我的数据框df2
包含以下变量:
EVTYPE TOTAL_FATALITIES TOTAL_INJURIES
(fctr) (dbl) (dbl)
1 TORNADO 5633 91346
2 EXCESSIVE HEAT 1903 6525
3 FLASH FLOOD 978 1777
4 HEAT 937 2100
5 LIGHTNING 816 5230
6 TSTM WIND 504 6957
> df2$TOTAL_FATALITIES
[1] 5633 1903 978 937 816 504 470 368 248 224 206 204 172 160 133 127 103 101 101
> df2$EVTYPE
[1] TORNADO EXCESSIVE HEAT FLASH FLOOD HEAT LIGHTNING
[6] TSTM WIND FLOOD RIP CURRENT HIGH WIND AVALANCHE
[11] WINTER STORM RIP CURRENTS HEAT WAVE EXTREME COLD THUNDERSTORM WIND
[16] HEAVY SNOW STRONG WIND BLIZZARD HIGH SURF
985 Levels: HIGH SURF ADVISORY COASTAL FLOOD FLASH FLOOD LIGHTNING ... WND
> df2$TOTAL_INJURIES
[1] 91346 6525 1777 2100 5230 6957 6789 232 1137 170 1321 297 309 231 1488 1021
[17] 280 805 152
我正在尝试创建一个名为SevType
的新列 - 我将存储一个值是受伤还是致命的。
但是,当我在df2$EVTYPE
上使用cbind时,它会将因子转换为数字,如下所示。
> head(cbind(Event=df2$EVTYPE,Total = df2$TOTAL_INJURIES,Severity="INJURE"))
Event Total Severity
[1,] "834" "91346" "INJURE"
[2,] "130" "6525" "INJURE"
[3,] "153" "1777" "INJURE"
[4,] "275" "2100" "INJURE"
[5,] "464" "5230" "INJURE"
[6,] "856" "6957" "INJURE"
请注意,[1,]处的Event
已从TORNADO更改为834.
有关为何发生这种情况的任何提示?