Monday, October 12, 2009

sorting a dataframe

To order selected variables in a dataframe you need to use the "order" and not the "sort" function. The easiest way to do this is to use the numerical (square bracket) notation system.

Specify the dataframe (lets call it "stations") and in the place where you would usually specify which rows to use place the command....

order(variable to order by).

So ..

station[order(station$V4),2:4]

will produce a data frame composed of the 2nd 3rd and 4th variables of the station dataset. However it will now be ordered by the variable called "V4".

No comments:

Post a Comment