Re: [R] tables with row sorted numerically although factors

2013-10-08 Thread Greg Snow
The order in the table is the order of the levels in the factor, so the best thing to do is to set the order in the factor itself. You can do this using the factor function when you create the factor, or with a function like relevel after the function has been created. In your case, what happens

Re: [R] tables with row sorted numerically although factors

2013-10-08 Thread David Winsemius
On Oct 8, 2013, at 10:29 AM, Renger van Nieuwkoop wrote: > Hi > I am using the package tables and want to have the rows in the numerical > order and not in the alphabetical order: > > library(tables) > Nodes <- c(1,10,20,2) > Values<- c(1,2,3,4) > Data <- data.frame(cbind(Nodes,Val

Re: [R] tables with row sorted numerically although factors

2013-10-08 Thread Rui Barradas
Hello, First of all, there's no need for data.frame(cbind(...)). data.frame() only will do the job, and it's less error prone. As for the question, since the column Nodes is to become a factor, why use as.character()? Without it the problem is solved: data <- data.frame(Nodes,Values)

[R] tables with row sorted numerically although factors

2013-10-08 Thread Renger van Nieuwkoop
Hi I am using the package tables and want to have the rows in the numerical order and not in the alphabetical order: library(tables) Nodes <- c(1,10,20,2) Values<- c(1,2,3,4) Data <- data.frame(cbind(Nodes,Values)) data$Nodes<- as.factor(as.character(data$Nodes)) # necessary to get f