我想将列值替换为lut
中定义的列值:
library("hflights")
library(dplyr) # For tbl_df
hflights <- tbl_df(hflights)
glimpse(hflights)
lut <- c("AA" = "American", "AS" = "Alaska", "B6" = "JetBlue", "CO" = "Continental", "DL" = "Delta", "OO" = "SkyWest", "UA" = "United", "US" = "US_Airways", "WN" = "Southwest", "EV" = "Atlantic_Southeast", "F9" = "Frontier", "FL" = "AirTran", "MQ" = "American_Eagle", "XE" = "ExpressJet", "YV" = "Mesa")
carriers <- hflights$UniqueCarrier
carriers <- lut[carriers]
hflights$UniqueCarrier <- carriers
glimpse(hflights)
lut <- c ("A" = "carrier", "B" = "weather", "C" = "FFA", "D" = "security", "E" = "not cancelled")
cancellation <- hflights$CancellationCode
cancellation <- lut[cancellation]
hflights$CancellationCode <- cancellation
glimpse(hflights)
当我使用hflights <- tbl_df(hflights)
时,两个替换操作都失败,我得到相应列的NA值,但是当我不使用tbl
包中的dplyr
时,第一个一个是成功的但是对于第二个我得到NA值。 hflights
是包含休斯顿航班数据的包。我怎么了?抱歉我的英语不好!