Skip to content
Prev 126021 / 398500 Next

Factor levels.

Rolf Turner wrote:
You didn't say that fff was numeric.

If fff is a factor, then we have the problem:

 > attach(read.table(stdin(),header=T))
0: fff
1: Unit
2: Scholarship
3: Scholarship
4: Unit
5:
 > c("U","A","S")[fff]
[1] "A" "U" "U" "A"

Actually we have another problem too, namely sort order....

Anyway, sort the labels, and

 > c("A","S", "U")[fff]
[1] "S" "A" "A" "S"

If you have the data as numeric codes, then of course

factor(fff, levels=1:3, labels=c("U","A","S"))

does the trick too.