Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
次の行に沿って、任意の数のグループと任意の値を持つグループ化/因子変数を表す任意の長さのベクトルまたは列があるとします。
a <- c(2,2,2,2,2,7,7,7,7,10,10,10,10,10) a [1] 2 2 2 2 2 7 7 7 7 10 10 10 10 10
それを最も簡単にこれに変える方法は次のとおりです。
a [1] 1 1 1 1 1 2 2 2 2 3 3 3 3 3
a <- c(2,2,2,2,2,7,7,7,7,10,10,10,10,10) c(factor(a)) #[1] 1 1 1 1 1 2 2 2 2 3 3 3 3 3
説明:
levels因子は、属性とクラス属性を持つ単なる整数ベクトルです。c副作用として属性を削除します。as.numericorのas.integer代わりにc、それぞれ同様の結果または同じ結果を使用できます。
levels
c
as.numeric
as.integer