不确定为什么会发生这种情况。我有一个包含以下变量的数据框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。
这是为什么发生的提示?