Adding a row upwards in R











up vote
0
down vote

favorite












I'm using a recursive algorithm to generate samples and include them in a list. For that I was using rbind (since I dont know the final number of rows, so I cant just declare it and access trough list[i, ] to attribute the values).
The problem is I start sampling from the last value to the first, so my list is upside down.



Is there a way to use rbind to create a row upwards instead of downwards?



Example for ilustration:
Suppose you have x1 = c(1, 2) and x2 = c(3, 4)
if you do: rbind(x1, x2) you get:



1 2
3 4


But what I need is:



3 4
1 2


Remember that I cant just do rbind(x2, x1), because I'm sampling backwards, so I don't have all values before binding.










share|improve this question
























  • I am probably missing something but what about rev at the end. Then your list is in the "correct" order.
    – Ian Wesley
    Nov 21 at 16:49












  • That is exactly what I need. I didn't know about this function. Thanks! But still, is there some way to do it directly?
    – Arthur T
    Nov 21 at 16:52












  • Can you modify your example to show why rbind(x2, x1) doesn't work? Because it seems like at whatever point you rbind, you have the values to bind, so switching the order should work...
    – Gregor
    Nov 21 at 16:58










  • You would just switch the order of your rbind. As in rbind(newobject, oldobject), but you said that did not work for some reason.
    – Ian Wesley
    Nov 21 at 17:02












  • I cant see why you could not make that work with a recursive function, but it probably does not match the function you have.
    – Ian Wesley
    Nov 21 at 17:05















up vote
0
down vote

favorite












I'm using a recursive algorithm to generate samples and include them in a list. For that I was using rbind (since I dont know the final number of rows, so I cant just declare it and access trough list[i, ] to attribute the values).
The problem is I start sampling from the last value to the first, so my list is upside down.



Is there a way to use rbind to create a row upwards instead of downwards?



Example for ilustration:
Suppose you have x1 = c(1, 2) and x2 = c(3, 4)
if you do: rbind(x1, x2) you get:



1 2
3 4


But what I need is:



3 4
1 2


Remember that I cant just do rbind(x2, x1), because I'm sampling backwards, so I don't have all values before binding.










share|improve this question
























  • I am probably missing something but what about rev at the end. Then your list is in the "correct" order.
    – Ian Wesley
    Nov 21 at 16:49












  • That is exactly what I need. I didn't know about this function. Thanks! But still, is there some way to do it directly?
    – Arthur T
    Nov 21 at 16:52












  • Can you modify your example to show why rbind(x2, x1) doesn't work? Because it seems like at whatever point you rbind, you have the values to bind, so switching the order should work...
    – Gregor
    Nov 21 at 16:58










  • You would just switch the order of your rbind. As in rbind(newobject, oldobject), but you said that did not work for some reason.
    – Ian Wesley
    Nov 21 at 17:02












  • I cant see why you could not make that work with a recursive function, but it probably does not match the function you have.
    – Ian Wesley
    Nov 21 at 17:05













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm using a recursive algorithm to generate samples and include them in a list. For that I was using rbind (since I dont know the final number of rows, so I cant just declare it and access trough list[i, ] to attribute the values).
The problem is I start sampling from the last value to the first, so my list is upside down.



Is there a way to use rbind to create a row upwards instead of downwards?



Example for ilustration:
Suppose you have x1 = c(1, 2) and x2 = c(3, 4)
if you do: rbind(x1, x2) you get:



1 2
3 4


But what I need is:



3 4
1 2


Remember that I cant just do rbind(x2, x1), because I'm sampling backwards, so I don't have all values before binding.










share|improve this question















I'm using a recursive algorithm to generate samples and include them in a list. For that I was using rbind (since I dont know the final number of rows, so I cant just declare it and access trough list[i, ] to attribute the values).
The problem is I start sampling from the last value to the first, so my list is upside down.



Is there a way to use rbind to create a row upwards instead of downwards?



Example for ilustration:
Suppose you have x1 = c(1, 2) and x2 = c(3, 4)
if you do: rbind(x1, x2) you get:



1 2
3 4


But what I need is:



3 4
1 2


Remember that I cant just do rbind(x2, x1), because I'm sampling backwards, so I don't have all values before binding.







r sorting smoothing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 16:52









J.R.

3,20811219




3,20811219










asked Nov 21 at 16:46









Arthur T

82




82












  • I am probably missing something but what about rev at the end. Then your list is in the "correct" order.
    – Ian Wesley
    Nov 21 at 16:49












  • That is exactly what I need. I didn't know about this function. Thanks! But still, is there some way to do it directly?
    – Arthur T
    Nov 21 at 16:52












  • Can you modify your example to show why rbind(x2, x1) doesn't work? Because it seems like at whatever point you rbind, you have the values to bind, so switching the order should work...
    – Gregor
    Nov 21 at 16:58










  • You would just switch the order of your rbind. As in rbind(newobject, oldobject), but you said that did not work for some reason.
    – Ian Wesley
    Nov 21 at 17:02












  • I cant see why you could not make that work with a recursive function, but it probably does not match the function you have.
    – Ian Wesley
    Nov 21 at 17:05


















  • I am probably missing something but what about rev at the end. Then your list is in the "correct" order.
    – Ian Wesley
    Nov 21 at 16:49












  • That is exactly what I need. I didn't know about this function. Thanks! But still, is there some way to do it directly?
    – Arthur T
    Nov 21 at 16:52












  • Can you modify your example to show why rbind(x2, x1) doesn't work? Because it seems like at whatever point you rbind, you have the values to bind, so switching the order should work...
    – Gregor
    Nov 21 at 16:58










  • You would just switch the order of your rbind. As in rbind(newobject, oldobject), but you said that did not work for some reason.
    – Ian Wesley
    Nov 21 at 17:02












  • I cant see why you could not make that work with a recursive function, but it probably does not match the function you have.
    – Ian Wesley
    Nov 21 at 17:05
















I am probably missing something but what about rev at the end. Then your list is in the "correct" order.
– Ian Wesley
Nov 21 at 16:49






I am probably missing something but what about rev at the end. Then your list is in the "correct" order.
– Ian Wesley
Nov 21 at 16:49














That is exactly what I need. I didn't know about this function. Thanks! But still, is there some way to do it directly?
– Arthur T
Nov 21 at 16:52






That is exactly what I need. I didn't know about this function. Thanks! But still, is there some way to do it directly?
– Arthur T
Nov 21 at 16:52














Can you modify your example to show why rbind(x2, x1) doesn't work? Because it seems like at whatever point you rbind, you have the values to bind, so switching the order should work...
– Gregor
Nov 21 at 16:58




Can you modify your example to show why rbind(x2, x1) doesn't work? Because it seems like at whatever point you rbind, you have the values to bind, so switching the order should work...
– Gregor
Nov 21 at 16:58












You would just switch the order of your rbind. As in rbind(newobject, oldobject), but you said that did not work for some reason.
– Ian Wesley
Nov 21 at 17:02






You would just switch the order of your rbind. As in rbind(newobject, oldobject), but you said that did not work for some reason.
– Ian Wesley
Nov 21 at 17:02














I cant see why you could not make that work with a recursive function, but it probably does not match the function you have.
– Ian Wesley
Nov 21 at 17:05




I cant see why you could not make that work with a recursive function, but it probably does not match the function you have.
– Ian Wesley
Nov 21 at 17:05

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416859%2fadding-a-row-upwards-in-r%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416859%2fadding-a-row-upwards-in-r%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Berounka

Fiat S.p.A.

Type 'String' is not a subtype of type 'int' of 'index'