-1
我有一個分類變量educa
,爲了便於閱讀,需要將其轉換爲數字。 educa
可以採用6個值。我想將它們轉換爲1-6。我該怎麼做呢?這是行不通的:將分類變量轉換爲數字
brfs2013educationsummarycleaned <-
brfs2013educationsummary %>%
mutate(
educa_level = ifelse(educa == "Never attended school or only kindergarten", 1, educat == "Grades 1 through 8 (Elementary)", 2, "not a real category"))
我在做什麼錯?以上是我打算做的一部分。
你可以使用'factor's –
你能提供一個數據樣本嗎? –