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.
r sorting smoothing
add a comment |
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.
r sorting smoothing
I am probably missing something but what aboutrev
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 whyrbind(x2, x1)
doesn't work? Because it seems like at whatever point yourbind
, 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 yourrbind
. As inrbind(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
add a comment |
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.
r sorting smoothing
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
r sorting smoothing
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 aboutrev
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 whyrbind(x2, x1)
doesn't work? Because it seems like at whatever point yourbind
, 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 yourrbind
. As inrbind(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
add a comment |
I am probably missing something but what aboutrev
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 whyrbind(x2, x1)
doesn't work? Because it seems like at whatever point yourbind
, 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 yourrbind
. As inrbind(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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 yourbind
, 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 inrbind(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