Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6728943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:13:48+00:00 2026-05-26T10:13:48+00:00

In R I have a data frame with 9 named columns, describing experimental data.

  • 0

In R I have a data frame with 9 named columns, describing experimental data. The first column contains gene names, and the following 8 columns contain gene expression values. The ultimate goal is to sort the data frame by the standard deviation of the expression values.

Basically, I want to compute the standard deviation of columns 2 to 9 and sort the entire data frame according to these values. How can I do that?

My first idea was to add a tenth column with the standard deviation, computed using the sd() function, then sorting the table, finally deleting the tenth column again. But I can not figure out how to do that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:13:48+00:00Added an answer on May 26, 2026 at 10:13 am

    The key commands are: apply, order, and some row rearrangement.

    ##Create some dummy data
    ##You should always try and include some test data in your questions
    R> dd = as.data.frame(matrix(rnorm(80), ncol=8))
    R> dd = cbind(GENE = LETTERS[1:10], dd)
    R> head(dd, 2)
       GENE    V1     V2      V3      V4      V5     V6      V7      V8
     1    A 1.693 1.2977  1.2220  0.4877 -1.7076 1.7796  0.7980 0.08643
     2    B 1.987 0.1545 -0.2173 -0.5959  0.7274 0.2757 -0.5391 0.56054
    
    ##Work out the sd for columns 2 to 9 using apply
    ##Use "order" to reorder the rows
    R> dd1 = dd[order(apply(dd[,2:9], 1, sd)),]
    ##Check the new order
    R> apply(dd1[,2:9], 1, sd)
         8      7      5      9      2      1      4      6     10      3 
    0.5197 0.7128 0.8149 0.8210 0.8624 0.8808 0.9804 1.2058 1.5086 1.6191 
    R> head(dd1, 2)
      GENE      V1      V2     V3      V4      V5      V6       V7       V8
    8    H -0.3869  0.6206  0.279 -0.3867 -0.4915 -1.0979 -0.07696 -0.09097
    7    G -1.2966 -1.1279 -1.082 -0.4739  0.2717 -0.1365  0.38614  0.38445
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data frame with two columns. First column contains categories such as
I have a data frame with 22239 rows & 200 columns. The first column
I have a data.frame in R. It contains a lot of data : gene
I have a data.frame named d of ~1,300,000 lines and 4 columns and another
I have a data.frame with 2 columns: Node A, Node B. Each entry in
I have a data frame where one particular column has a set of specific
Suppose that you have a data frame with many rows and many columns. The
I have a data frame filled with factor columns, and I want to add
I have a large data frame (named z ) that looks like this: RPos
If I have a data frame where I am adding columns, and I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.