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 7039641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:49:23+00:00 2026-05-28T01:49:23+00:00

Here is my dataset. set.seed (1234) mydf <- data.frame (Id = c(dis, 1:5), V1.a

  • 0

Here is my dataset.

set.seed (1234) 
mydf <- data.frame (Id = c("dis", 1:5),

V1.a = c(0,sample(c(0, 1,2), 5, replace = T)),V1.b = c(0,sample(c(0, 1,2), 5, replace = T)),
V2.a = c(1.5,sample(c(0, 1,2), 5, replace = T)),V2.b = c(1.5,sample(c(0, 1,2), 5, replace = T)),
V3.a = c(2.0,sample(c(0, 1,2), 5, replace = T)),V3.b = c(2.0,sample(c(0, 1,2), 5, replace = T)),
V4.a = c(5.0,sample(c(0, 1,2), 5, replace = T)),V4.b = c(5.0,sample(c(0, 1,2), 5, replace = T)),
V5.a = c(6.0,sample(c(0, 1,2), 5, replace = T)),V5.b = c(6.0,sample(c(0, 1,2), 5, replace = T)),
V16a = c(11.0,sample(c(0, 1,2), 5, replace = T)),V6.b = c(11.0,sample(c(0, 1,2), 5, replace = T)),
V7.a = c(12.0,sample(c(0, 1,2), 5, replace = T)),V7.b = c(12.0,sample(c(0, 1,2), 5, replace = T)),
V8.a = c(3.0,sample(c(0, 1,2), 5, replace = T)),V8.b = c(3.0,sample(c(0, 1,2), 5, replace = T)))

 d = mydf
> d
  Id V1.a V1.b V2.a V2.b V3.a V3.b V4.a V4.b V5.a V5.b V16a V6.b V7.a V7.b V8.a
1  0    0    0  1.5  1.5    2    2    5    5    6    6   11   11   12   12    3
2  1    1    2  1.0  0.0    1    2    1    2    0    1    1    2    0    1    1
3  2    1    1  2.0  2.0    1    2    0    1    0    1    1    1    0    2    0
4  3    0    0  1.0  2.0    2    0    2    2    2    2    2    1    1    2    0
5  4    0    2  0.0  2.0    2    2    1    1    2    2    2    1    2    1    0
6  5    2    1  2.0  0.0    2    0    1    1    0    1    0    0    0    2    1
  V8.b
1    3
2    2
3    0
4    2
5    0
6    2

I wanted to order by value in first row element of each variable.

>  d <- d[,order(d[1,-1])]
> d
  Id V1.a V1.b V2.a V2.b V3.a V7.b V8.a V3.b V4.a V4.b V5.a V5.b V16a V6.b V7.a
1  0    0    0  1.5  1.5    2   12    3    2    5    5    6    6   11   11   12
2  1    1    2  1.0  0.0    1    1    1    2    1    2    0    1    1    2    0
3  2    1    1  2.0  2.0    1    2    0    2    0    1    0    1    1    1    0
4  3    0    0  1.0  2.0    2    2    0    0    2    2    2    2    2    1    1
5  4    0    2  0.0  2.0    2    1    0    2    1    1    2    2    2    1    2
6  5    2    1  2.0  0.0    2    2    1    0    1    1    0    1    0    0    0

Ordering is not working for V7.a! V8.a is missing. What is the problem or good way to do it some other way?

  • 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-28T01:49:24+00:00Added an answer on May 28, 2026 at 1:49 am

    The integer vector returned by order(d[1,-1]) refers to the data.frame d[,-1] (i.e. d with the first column removed). If you then use that vector to index the columns in d, you get a meaningless sorting of its columns (and you lose the final column altogether).

    This should fix the problem:

    d[,c(1, 1+ order(d[1,-1]))]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my small dataset set.seed(123) X1 <- rep(1:3, each = 4) X2 <-
I have the following sample dataset (below and/or as CSVs here: http://goo.gl/wK57T ) which
I wan't to create DataSet from code and set it as data source for
Background Here is my issue. Earlier in the course of my program a System.Data.DataSet
Here is my table in the dataset: SELECT tag_work_field.* FROM tag_work_field I created this
Here is a complete example. I want to forbid using A::set from objects casted
I have a set of data from a table ( TableA ) which relates
So I have a set of data that includes a column of dates and
I have a set a data that I need to calculate their consecutive mean
Using Regex in .Net I will have a set of data that comes in

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.