Tony Plate
2005-May-02 21:38 UTC
[R] summary(as.factor(x) - force to not sort the result according factor levels
Christoph Lehmann wrote:> Hi > The result of a summary(as.factor(x)) (see example below) call is sorted > according to the factor level. How can I get the result not sorted but > in the original order of the levels in x?by creating the factor with the levels in the order you want: > test <- c(120402, 120402, 120402, 1323, 1323,200393, 200393, 200393, 200393, 200393) > summary(factor(test, levels=unique(test))) 120402 1323 200393 3 2 5
Christoph Lehmann
2005-May-02 22:29 UTC
[R] summary(as.factor(x) - force to not sort the result according factor levels
Hi The result of a summary(as.factor(x)) (see example below) call is sorted according to the factor level. How can I get the result not sorted but in the original order of the levels in x? > test <- c(120402, 120402, 120402, 1323, 1323,200393, 200393, 200393, 200393, 200393) > summary(as.factor(test)) 1323 120402 200393 2 3 5 I need: 120402 1323 200393 3 2 5 thanks for a hint christoph
Sundar Dorai-Raj
2005-May-02 22:32 UTC
[R] summary(as.factor(x) - force to not sort the result according factor levels
Christoph Lehmann wrote on 5/2/2005 3:29 PM:> Hi > The result of a summary(as.factor(x)) (see example below) call is sorted > according to the factor level. How can I get the result not sorted but > in the original order of the levels in x? > > > > test <- c(120402, 120402, 120402, 1323, 1323,200393, 200393, 200393, > 200393, 200393) > > summary(as.factor(test)) > 1323 120402 200393 > 2 3 5 > > I need: > 120402 1323 200393 > 3 2 5 > > thanks for a hint > > christophUse the levels argument of ?factor. summary(factor(test, levels = unique(test))) --sundar