Skip to content
Prev 81944 / 398506 Next

about sorting table

on 12/1/2005 4:05 AM Martin Maechler said the following:
Yes, may I add this for Guillaume?  I like to think that "attach()" 
makes a *read-only* copy of the data frame's columns.  That may not be 
exactly what R does, but as a metaphor, it provides a way to think about 
what happens.

You can get what you wanted by

attach(tab)
... sorting code...
detach()
attach(tab)

but as Martin says, it is nicer to use 'with()' rather than 'attach()', 
and many functions do take a 'data=' argument.  (I hope that 'data=' 
will spread quickly to more R functions.)

If you search the archives, you will find a very nice function, 
'sort.data.frame()', by Kevin Wright.  It allows sorting by several 
columns and in ascending and descending order without writing the basic 
code each time.

MHP