[R] Relevel dynamically
    mails 
    mails00000 at gmail.com
       
    Mon Jan 16 14:53:25 CET 2012
    
    
  
Dear list,
I am running R code which produces a data.frame with variable rows. For
plotting purposes I need to relevel 
the column called "names" but since the dimension of the data.frame can vary
I do not know how to dynamically
revel the data.frame.
Here is an example data.frame called df to illustrate what I try to achieve:
> df <- data.frame(cbind(c("a","b","c","d","e"), c(5,6,4,8,9)))
> colnames(df) <- c("name", "value")
> df
  name value
1    a     5
2    b     6
3    c     4
4    d     8
5    e     9
Now the releveling:
df$name <- factor(df$name, levels=c("b","d","c","e","a"))
That was easy. But the plotting goes wrong when the data.frame has less
rows:
> df
  name value
1    a     5
4    d     8
5    e     9
Now my script runs the same line again:
df$name <- factor(df$name, levels=c("b","d","c","e","a"))
R does not throw any errors, however, lattice does not plot the results
correctly. So I dynamically create
a line which does the following: df$name <- factor(df$name,
levels=c("d","e","a"))
Thanks for any advice in advance!
Cheers
--
View this message in context: http://r.789695.n4.nabble.com/Relevel-dynamically-tp4299531p4299531.html
Sent from the R help mailing list archive at Nabble.com.
    
    
More information about the R-help
mailing list