[R] Reordering Factors

arun smartpink111 at yahoo.com
Mon Mar 3 18:55:54 CET 2014


Hi,
Check if the condition is similar to below:
set.seed(28)

vec1 <- factor(sample(LETTERS[1:5],20,replace=TRUE),levels=c("B","C","D","A"))
levels(vec1)
#[1] "B" "C" "D" "A"
summary(vec1)
#   B    C    D    A NA's 
#   2    4    5    4    5 


A.K.
 



Hi, 

I am trying to reorder a set of football team names from 
Alphabetical order to the positions they finished last season, therefore
 using the best team as a reference point in my final model. 

When using the 
football$Attack<-factor(football$Attack, levels=c("Manchester 
United","Manchester Ciity","Chelsea","Arsenal",................") 

levels(football$Attack) 

showed the teams in the right order, however when I did a summary of the data it returned a lot of "NA" 


any idea how is best to succesfully reorder my data 

Thanks 

Stephen



More information about the R-help mailing list