Sort R data.frame by column

Load in your data and convert to a data.frame. I assume you have headers in your file, if you don’t change the True to False in the following:

data <- read.table("myfile.txt", header=True)

If you don’t want to keep typing data$column_name


To list the names of the columns, for reference


To sort the data.frame by a column, in this case dmFactorRMS


If you’ve bothered to bind data you can do


This won’t modify your input, therefore you will need to create a new varaible

sorted_data <- data[order(dmFactorRMS)]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s