Including 0s in the increasing order function in R [duplicate]












-1
















This question already has an answer here:




  • How to sort a dataframe by multiple column(s)?

    18 answers



  • Understanding the order() function

    6 answers




Can someone please explain why "0" is not included as the first unit to count when you do the order function? I have samples with IDs and they start at 0,1,2,3,4,...etc. When I do the order function, the ID numbers start at 1 rather than 0. Can someone explain why that is and also how to solve this problem?



I have a dataframe with several columns and one of the columns is ID and i want to sort the entire dataframe according to that column. The only thing is that I tried order, but it started at one. On excel, you can do custom sort and have it from smallest to largest. That's kind of what I am looking for, but I have tried everything and still nothing. Is there a way to do this?



UPDATE: So I learned what was going wrong. So the 0s were being eliminated due to running certain lines of code before others. I changed the order to be the ideal order of lines running, I fixed it and once I ran order() again, this time it did start at 0 and did not delete the 0s. I know that this was a stupid mistake and oversight, and I apologize to all of you that had to read this atrocious question, especially since I am new to R. Thank you all for your help.










share|improve this question















marked as duplicate by user2554330, joran r
Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 15 '18 at 20:25


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    order gives the index. Indexing in R starts at 1. You need vec[order(vec)] or more easily sort(vec)

    – akrun
    Nov 15 '18 at 19:41








  • 1





    If the vector to be ordered has a zero it will be included. As a matter of fact, you can even order negative values. But the return value of order starts at 1`.

    – Rui Barradas
    Nov 15 '18 at 19:43











  • I have a dataframe with several columns and one of the columns is ID and i want to sort the entire dataframe according to that column. The only thing is that I tried order, but it started at one. On excel, you can do custom sort and have it from smallest to largest. That's kind of what I am looking for, but I have tried everything and still nothing.

    – Lasarus9
    Nov 15 '18 at 19:59
















-1
















This question already has an answer here:




  • How to sort a dataframe by multiple column(s)?

    18 answers



  • Understanding the order() function

    6 answers




Can someone please explain why "0" is not included as the first unit to count when you do the order function? I have samples with IDs and they start at 0,1,2,3,4,...etc. When I do the order function, the ID numbers start at 1 rather than 0. Can someone explain why that is and also how to solve this problem?



I have a dataframe with several columns and one of the columns is ID and i want to sort the entire dataframe according to that column. The only thing is that I tried order, but it started at one. On excel, you can do custom sort and have it from smallest to largest. That's kind of what I am looking for, but I have tried everything and still nothing. Is there a way to do this?



UPDATE: So I learned what was going wrong. So the 0s were being eliminated due to running certain lines of code before others. I changed the order to be the ideal order of lines running, I fixed it and once I ran order() again, this time it did start at 0 and did not delete the 0s. I know that this was a stupid mistake and oversight, and I apologize to all of you that had to read this atrocious question, especially since I am new to R. Thank you all for your help.










share|improve this question















marked as duplicate by user2554330, joran r
Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 15 '18 at 20:25


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    order gives the index. Indexing in R starts at 1. You need vec[order(vec)] or more easily sort(vec)

    – akrun
    Nov 15 '18 at 19:41








  • 1





    If the vector to be ordered has a zero it will be included. As a matter of fact, you can even order negative values. But the return value of order starts at 1`.

    – Rui Barradas
    Nov 15 '18 at 19:43











  • I have a dataframe with several columns and one of the columns is ID and i want to sort the entire dataframe according to that column. The only thing is that I tried order, but it started at one. On excel, you can do custom sort and have it from smallest to largest. That's kind of what I am looking for, but I have tried everything and still nothing.

    – Lasarus9
    Nov 15 '18 at 19:59














-1












-1








-1









This question already has an answer here:




  • How to sort a dataframe by multiple column(s)?

    18 answers



  • Understanding the order() function

    6 answers




Can someone please explain why "0" is not included as the first unit to count when you do the order function? I have samples with IDs and they start at 0,1,2,3,4,...etc. When I do the order function, the ID numbers start at 1 rather than 0. Can someone explain why that is and also how to solve this problem?



I have a dataframe with several columns and one of the columns is ID and i want to sort the entire dataframe according to that column. The only thing is that I tried order, but it started at one. On excel, you can do custom sort and have it from smallest to largest. That's kind of what I am looking for, but I have tried everything and still nothing. Is there a way to do this?



UPDATE: So I learned what was going wrong. So the 0s were being eliminated due to running certain lines of code before others. I changed the order to be the ideal order of lines running, I fixed it and once I ran order() again, this time it did start at 0 and did not delete the 0s. I know that this was a stupid mistake and oversight, and I apologize to all of you that had to read this atrocious question, especially since I am new to R. Thank you all for your help.










share|improve this question

















This question already has an answer here:




  • How to sort a dataframe by multiple column(s)?

    18 answers



  • Understanding the order() function

    6 answers




Can someone please explain why "0" is not included as the first unit to count when you do the order function? I have samples with IDs and they start at 0,1,2,3,4,...etc. When I do the order function, the ID numbers start at 1 rather than 0. Can someone explain why that is and also how to solve this problem?



I have a dataframe with several columns and one of the columns is ID and i want to sort the entire dataframe according to that column. The only thing is that I tried order, but it started at one. On excel, you can do custom sort and have it from smallest to largest. That's kind of what I am looking for, but I have tried everything and still nothing. Is there a way to do this?



UPDATE: So I learned what was going wrong. So the 0s were being eliminated due to running certain lines of code before others. I changed the order to be the ideal order of lines running, I fixed it and once I ran order() again, this time it did start at 0 and did not delete the 0s. I know that this was a stupid mistake and oversight, and I apologize to all of you that had to read this atrocious question, especially since I am new to R. Thank you all for your help.





This question already has an answer here:




  • How to sort a dataframe by multiple column(s)?

    18 answers



  • Understanding the order() function

    6 answers








r function






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 18 at 16:54







Lasarus9

















asked Nov 15 '18 at 19:38









Lasarus9Lasarus9

558




558




marked as duplicate by user2554330, joran r
Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 15 '18 at 20:25


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by user2554330, joran r
Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 15 '18 at 20:25


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1





    order gives the index. Indexing in R starts at 1. You need vec[order(vec)] or more easily sort(vec)

    – akrun
    Nov 15 '18 at 19:41








  • 1





    If the vector to be ordered has a zero it will be included. As a matter of fact, you can even order negative values. But the return value of order starts at 1`.

    – Rui Barradas
    Nov 15 '18 at 19:43











  • I have a dataframe with several columns and one of the columns is ID and i want to sort the entire dataframe according to that column. The only thing is that I tried order, but it started at one. On excel, you can do custom sort and have it from smallest to largest. That's kind of what I am looking for, but I have tried everything and still nothing.

    – Lasarus9
    Nov 15 '18 at 19:59














  • 1





    order gives the index. Indexing in R starts at 1. You need vec[order(vec)] or more easily sort(vec)

    – akrun
    Nov 15 '18 at 19:41








  • 1





    If the vector to be ordered has a zero it will be included. As a matter of fact, you can even order negative values. But the return value of order starts at 1`.

    – Rui Barradas
    Nov 15 '18 at 19:43











  • I have a dataframe with several columns and one of the columns is ID and i want to sort the entire dataframe according to that column. The only thing is that I tried order, but it started at one. On excel, you can do custom sort and have it from smallest to largest. That's kind of what I am looking for, but I have tried everything and still nothing.

    – Lasarus9
    Nov 15 '18 at 19:59








1




1





order gives the index. Indexing in R starts at 1. You need vec[order(vec)] or more easily sort(vec)

– akrun
Nov 15 '18 at 19:41







order gives the index. Indexing in R starts at 1. You need vec[order(vec)] or more easily sort(vec)

– akrun
Nov 15 '18 at 19:41






1




1





If the vector to be ordered has a zero it will be included. As a matter of fact, you can even order negative values. But the return value of order starts at 1`.

– Rui Barradas
Nov 15 '18 at 19:43





If the vector to be ordered has a zero it will be included. As a matter of fact, you can even order negative values. But the return value of order starts at 1`.

– Rui Barradas
Nov 15 '18 at 19:43













I have a dataframe with several columns and one of the columns is ID and i want to sort the entire dataframe according to that column. The only thing is that I tried order, but it started at one. On excel, you can do custom sort and have it from smallest to largest. That's kind of what I am looking for, but I have tried everything and still nothing.

– Lasarus9
Nov 15 '18 at 19:59





I have a dataframe with several columns and one of the columns is ID and i want to sort the entire dataframe according to that column. The only thing is that I tried order, but it started at one. On excel, you can do custom sort and have it from smallest to largest. That's kind of what I am looking for, but I have tried everything and still nothing.

– Lasarus9
Nov 15 '18 at 19:59












1 Answer
1






active

oldest

votes


















3














Order returns the index values of the elements in a vector in a sorted order, so that, for example:



x<-c(5,3,0,7)
order(x)
[1] 3 2 1 4

x[order(x)]
[1] 0 3 5 7


This is useful if, for example, you want to sort one vector by the order of another.



If you want the response to be the actual vector values sorted in order, use sort:



sort(x)
[1] 0 3 5 7





share|improve this answer
























  • I have a dataframe with several columns and one of the columns is ID and i want to sort the entire dataframe according to that column. The only thing is that I tried order, but it started at one. On excel, you can do custom sort and have it from smallest to largest. That's kind of what I am looking for, but I have tried everything and still nothing.

    – Lasarus9
    Nov 15 '18 at 19:58






  • 1





    if you run df[order(df$id),], your df will be re-ordered with the lowest ID (0, in this case) at the top. Alternatively, if you want to use the tidyverse, you can do arrange(df, id).

    – iod
    Nov 15 '18 at 20:53


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














Order returns the index values of the elements in a vector in a sorted order, so that, for example:



x<-c(5,3,0,7)
order(x)
[1] 3 2 1 4

x[order(x)]
[1] 0 3 5 7


This is useful if, for example, you want to sort one vector by the order of another.



If you want the response to be the actual vector values sorted in order, use sort:



sort(x)
[1] 0 3 5 7





share|improve this answer
























  • I have a dataframe with several columns and one of the columns is ID and i want to sort the entire dataframe according to that column. The only thing is that I tried order, but it started at one. On excel, you can do custom sort and have it from smallest to largest. That's kind of what I am looking for, but I have tried everything and still nothing.

    – Lasarus9
    Nov 15 '18 at 19:58






  • 1





    if you run df[order(df$id),], your df will be re-ordered with the lowest ID (0, in this case) at the top. Alternatively, if you want to use the tidyverse, you can do arrange(df, id).

    – iod
    Nov 15 '18 at 20:53
















3














Order returns the index values of the elements in a vector in a sorted order, so that, for example:



x<-c(5,3,0,7)
order(x)
[1] 3 2 1 4

x[order(x)]
[1] 0 3 5 7


This is useful if, for example, you want to sort one vector by the order of another.



If you want the response to be the actual vector values sorted in order, use sort:



sort(x)
[1] 0 3 5 7





share|improve this answer
























  • I have a dataframe with several columns and one of the columns is ID and i want to sort the entire dataframe according to that column. The only thing is that I tried order, but it started at one. On excel, you can do custom sort and have it from smallest to largest. That's kind of what I am looking for, but I have tried everything and still nothing.

    – Lasarus9
    Nov 15 '18 at 19:58






  • 1





    if you run df[order(df$id),], your df will be re-ordered with the lowest ID (0, in this case) at the top. Alternatively, if you want to use the tidyverse, you can do arrange(df, id).

    – iod
    Nov 15 '18 at 20:53














3












3








3







Order returns the index values of the elements in a vector in a sorted order, so that, for example:



x<-c(5,3,0,7)
order(x)
[1] 3 2 1 4

x[order(x)]
[1] 0 3 5 7


This is useful if, for example, you want to sort one vector by the order of another.



If you want the response to be the actual vector values sorted in order, use sort:



sort(x)
[1] 0 3 5 7





share|improve this answer













Order returns the index values of the elements in a vector in a sorted order, so that, for example:



x<-c(5,3,0,7)
order(x)
[1] 3 2 1 4

x[order(x)]
[1] 0 3 5 7


This is useful if, for example, you want to sort one vector by the order of another.



If you want the response to be the actual vector values sorted in order, use sort:



sort(x)
[1] 0 3 5 7






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 19:43









iodiod

4,1512723




4,1512723













  • I have a dataframe with several columns and one of the columns is ID and i want to sort the entire dataframe according to that column. The only thing is that I tried order, but it started at one. On excel, you can do custom sort and have it from smallest to largest. That's kind of what I am looking for, but I have tried everything and still nothing.

    – Lasarus9
    Nov 15 '18 at 19:58






  • 1





    if you run df[order(df$id),], your df will be re-ordered with the lowest ID (0, in this case) at the top. Alternatively, if you want to use the tidyverse, you can do arrange(df, id).

    – iod
    Nov 15 '18 at 20:53



















  • I have a dataframe with several columns and one of the columns is ID and i want to sort the entire dataframe according to that column. The only thing is that I tried order, but it started at one. On excel, you can do custom sort and have it from smallest to largest. That's kind of what I am looking for, but I have tried everything and still nothing.

    – Lasarus9
    Nov 15 '18 at 19:58






  • 1





    if you run df[order(df$id),], your df will be re-ordered with the lowest ID (0, in this case) at the top. Alternatively, if you want to use the tidyverse, you can do arrange(df, id).

    – iod
    Nov 15 '18 at 20:53

















I have a dataframe with several columns and one of the columns is ID and i want to sort the entire dataframe according to that column. The only thing is that I tried order, but it started at one. On excel, you can do custom sort and have it from smallest to largest. That's kind of what I am looking for, but I have tried everything and still nothing.

– Lasarus9
Nov 15 '18 at 19:58





I have a dataframe with several columns and one of the columns is ID and i want to sort the entire dataframe according to that column. The only thing is that I tried order, but it started at one. On excel, you can do custom sort and have it from smallest to largest. That's kind of what I am looking for, but I have tried everything and still nothing.

– Lasarus9
Nov 15 '18 at 19:58




1




1





if you run df[order(df$id),], your df will be re-ordered with the lowest ID (0, in this case) at the top. Alternatively, if you want to use the tidyverse, you can do arrange(df, id).

– iod
Nov 15 '18 at 20:53





if you run df[order(df$id),], your df will be re-ordered with the lowest ID (0, in this case) at the top. Alternatively, if you want to use the tidyverse, you can do arrange(df, id).

– iod
Nov 15 '18 at 20:53





Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python