Triad sou.

2012-09-26から1日間の記事一覧

Recoding a factor variable in a data.frame by the levels() function

R

When you want to change the coding of a factor variable in R, you can use the levels() function. Recoding z as 1 = A, 2-6 = B, 7 = C d <- data.frame(z = gl(7, 1, 14)) d$zc <- factor(d$z) levels(d$zc) <- list(A = 1, B = 2:6, C = 7) d Result…