R - Add a column of data to an existing column in a dataframe [duplicate]











up vote
-1
down vote

favorite













This question already has an answer here:




  • Add row to dataframe

    8 answers




I'm trying to figure out how to append more data to an existing dataframe one column at a time. For example: I have this dataframe:



df <- data.frame("x" = c(1, 2, 3, 4, 5), "y" = c(0.255, 0.236, 0.587, 0.369, 0.789))


Here are additional data I want to append. I want to add x2 to the bottom of the x column and then add y2 to the bottom of the y column.



x2 <- c(6, 7, 8, 9, 10)
y2 <- c(0.236, 0.963, 0.356, 0.489, 0.333)


This is what I want the dataframe to look like after.



x      y
1 0.255
2 0.236
3 0.587
4 0.369
5 0.789
6 0.236
7 0.963
8 0.356
9 0.489
10 0.333









share|improve this question













marked as duplicate by Masoud, Rui Barradas, Ronak Shah 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 20 at 6:30


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.















  • or this one stackoverflow.com/questions/10358680/… or this one stackoverflow.com/questions/42229019/… or this one stackoverflow.com/questions/29402528/… or this one stackoverflow.com/questions/8169323/… or this one stackoverflow.com/questions/3402371/…
    – Masoud
    Nov 19 at 22:30















up vote
-1
down vote

favorite













This question already has an answer here:




  • Add row to dataframe

    8 answers




I'm trying to figure out how to append more data to an existing dataframe one column at a time. For example: I have this dataframe:



df <- data.frame("x" = c(1, 2, 3, 4, 5), "y" = c(0.255, 0.236, 0.587, 0.369, 0.789))


Here are additional data I want to append. I want to add x2 to the bottom of the x column and then add y2 to the bottom of the y column.



x2 <- c(6, 7, 8, 9, 10)
y2 <- c(0.236, 0.963, 0.356, 0.489, 0.333)


This is what I want the dataframe to look like after.



x      y
1 0.255
2 0.236
3 0.587
4 0.369
5 0.789
6 0.236
7 0.963
8 0.356
9 0.489
10 0.333









share|improve this question













marked as duplicate by Masoud, Rui Barradas, Ronak Shah 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 20 at 6:30


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.















  • or this one stackoverflow.com/questions/10358680/… or this one stackoverflow.com/questions/42229019/… or this one stackoverflow.com/questions/29402528/… or this one stackoverflow.com/questions/8169323/… or this one stackoverflow.com/questions/3402371/…
    – Masoud
    Nov 19 at 22:30













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite












This question already has an answer here:




  • Add row to dataframe

    8 answers




I'm trying to figure out how to append more data to an existing dataframe one column at a time. For example: I have this dataframe:



df <- data.frame("x" = c(1, 2, 3, 4, 5), "y" = c(0.255, 0.236, 0.587, 0.369, 0.789))


Here are additional data I want to append. I want to add x2 to the bottom of the x column and then add y2 to the bottom of the y column.



x2 <- c(6, 7, 8, 9, 10)
y2 <- c(0.236, 0.963, 0.356, 0.489, 0.333)


This is what I want the dataframe to look like after.



x      y
1 0.255
2 0.236
3 0.587
4 0.369
5 0.789
6 0.236
7 0.963
8 0.356
9 0.489
10 0.333









share|improve this question














This question already has an answer here:




  • Add row to dataframe

    8 answers




I'm trying to figure out how to append more data to an existing dataframe one column at a time. For example: I have this dataframe:



df <- data.frame("x" = c(1, 2, 3, 4, 5), "y" = c(0.255, 0.236, 0.587, 0.369, 0.789))


Here are additional data I want to append. I want to add x2 to the bottom of the x column and then add y2 to the bottom of the y column.



x2 <- c(6, 7, 8, 9, 10)
y2 <- c(0.236, 0.963, 0.356, 0.489, 0.333)


This is what I want the dataframe to look like after.



x      y
1 0.255
2 0.236
3 0.587
4 0.369
5 0.789
6 0.236
7 0.963
8 0.356
9 0.489
10 0.333




This question already has an answer here:




  • Add row to dataframe

    8 answers








r dataframe






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 at 22:21









Myco

227




227




marked as duplicate by Masoud, Rui Barradas, Ronak Shah 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 20 at 6:30


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 Masoud, Rui Barradas, Ronak Shah 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 20 at 6:30


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.














  • or this one stackoverflow.com/questions/10358680/… or this one stackoverflow.com/questions/42229019/… or this one stackoverflow.com/questions/29402528/… or this one stackoverflow.com/questions/8169323/… or this one stackoverflow.com/questions/3402371/…
    – Masoud
    Nov 19 at 22:30


















  • or this one stackoverflow.com/questions/10358680/… or this one stackoverflow.com/questions/42229019/… or this one stackoverflow.com/questions/29402528/… or this one stackoverflow.com/questions/8169323/… or this one stackoverflow.com/questions/3402371/…
    – Masoud
    Nov 19 at 22:30
















or this one stackoverflow.com/questions/10358680/… or this one stackoverflow.com/questions/42229019/… or this one stackoverflow.com/questions/29402528/… or this one stackoverflow.com/questions/8169323/… or this one stackoverflow.com/questions/3402371/…
– Masoud
Nov 19 at 22:30




or this one stackoverflow.com/questions/10358680/… or this one stackoverflow.com/questions/42229019/… or this one stackoverflow.com/questions/29402528/… or this one stackoverflow.com/questions/8169323/… or this one stackoverflow.com/questions/3402371/…
– Masoud
Nov 19 at 22:30












2 Answers
2






active

oldest

votes

















up vote
0
down vote



accepted










You will need to make sure that the column names are same when appending data.



In your case:



df2 <- data.frame(x2, y2)   #creating a dataframe
names(df2) <- names(df) #changing the column header names as this is a requirement for append

df <- rbind(df, df2) #appending





share|improve this answer

















  • 1




    Please provide dupes instead of posting answers, when applicable.
    – Masoud
    Nov 19 at 22:28


















up vote
0
down vote













This should do the trick, unless I am missing something:



df <- data.frame("x" = c(1, 2, 3, 4, 5), "y" = c(0.255, 0.236, 0.587, 0.369, 0.789))


Change the names of the data to be added to have the same name as the original dataframe



x <- c(6, 7, 8, 9, 10)
y <- c(0.236, 0.963, 0.356, 0.489, 0.333)
df2 <- bind_cols(list(x = x, y = y))
df3 <- bind_rows(list(df, df2))





share|improve this answer





















  • The above code can be fed multiple df/tibbles simultaneously without the use of a do.call loop as well. As below the names need to be constant between dataframes for them to line up.
    – André.B
    Nov 19 at 22:36


















2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










You will need to make sure that the column names are same when appending data.



In your case:



df2 <- data.frame(x2, y2)   #creating a dataframe
names(df2) <- names(df) #changing the column header names as this is a requirement for append

df <- rbind(df, df2) #appending





share|improve this answer

















  • 1




    Please provide dupes instead of posting answers, when applicable.
    – Masoud
    Nov 19 at 22:28















up vote
0
down vote



accepted










You will need to make sure that the column names are same when appending data.



In your case:



df2 <- data.frame(x2, y2)   #creating a dataframe
names(df2) <- names(df) #changing the column header names as this is a requirement for append

df <- rbind(df, df2) #appending





share|improve this answer

















  • 1




    Please provide dupes instead of posting answers, when applicable.
    – Masoud
    Nov 19 at 22:28













up vote
0
down vote



accepted







up vote
0
down vote



accepted






You will need to make sure that the column names are same when appending data.



In your case:



df2 <- data.frame(x2, y2)   #creating a dataframe
names(df2) <- names(df) #changing the column header names as this is a requirement for append

df <- rbind(df, df2) #appending





share|improve this answer












You will need to make sure that the column names are same when appending data.



In your case:



df2 <- data.frame(x2, y2)   #creating a dataframe
names(df2) <- names(df) #changing the column header names as this is a requirement for append

df <- rbind(df, df2) #appending






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 at 22:25









SmitM

1,0711111




1,0711111








  • 1




    Please provide dupes instead of posting answers, when applicable.
    – Masoud
    Nov 19 at 22:28














  • 1




    Please provide dupes instead of posting answers, when applicable.
    – Masoud
    Nov 19 at 22:28








1




1




Please provide dupes instead of posting answers, when applicable.
– Masoud
Nov 19 at 22:28




Please provide dupes instead of posting answers, when applicable.
– Masoud
Nov 19 at 22:28












up vote
0
down vote













This should do the trick, unless I am missing something:



df <- data.frame("x" = c(1, 2, 3, 4, 5), "y" = c(0.255, 0.236, 0.587, 0.369, 0.789))


Change the names of the data to be added to have the same name as the original dataframe



x <- c(6, 7, 8, 9, 10)
y <- c(0.236, 0.963, 0.356, 0.489, 0.333)
df2 <- bind_cols(list(x = x, y = y))
df3 <- bind_rows(list(df, df2))





share|improve this answer





















  • The above code can be fed multiple df/tibbles simultaneously without the use of a do.call loop as well. As below the names need to be constant between dataframes for them to line up.
    – André.B
    Nov 19 at 22:36















up vote
0
down vote













This should do the trick, unless I am missing something:



df <- data.frame("x" = c(1, 2, 3, 4, 5), "y" = c(0.255, 0.236, 0.587, 0.369, 0.789))


Change the names of the data to be added to have the same name as the original dataframe



x <- c(6, 7, 8, 9, 10)
y <- c(0.236, 0.963, 0.356, 0.489, 0.333)
df2 <- bind_cols(list(x = x, y = y))
df3 <- bind_rows(list(df, df2))





share|improve this answer





















  • The above code can be fed multiple df/tibbles simultaneously without the use of a do.call loop as well. As below the names need to be constant between dataframes for them to line up.
    – André.B
    Nov 19 at 22:36













up vote
0
down vote










up vote
0
down vote









This should do the trick, unless I am missing something:



df <- data.frame("x" = c(1, 2, 3, 4, 5), "y" = c(0.255, 0.236, 0.587, 0.369, 0.789))


Change the names of the data to be added to have the same name as the original dataframe



x <- c(6, 7, 8, 9, 10)
y <- c(0.236, 0.963, 0.356, 0.489, 0.333)
df2 <- bind_cols(list(x = x, y = y))
df3 <- bind_rows(list(df, df2))





share|improve this answer












This should do the trick, unless I am missing something:



df <- data.frame("x" = c(1, 2, 3, 4, 5), "y" = c(0.255, 0.236, 0.587, 0.369, 0.789))


Change the names of the data to be added to have the same name as the original dataframe



x <- c(6, 7, 8, 9, 10)
y <- c(0.236, 0.963, 0.356, 0.489, 0.333)
df2 <- bind_cols(list(x = x, y = y))
df3 <- bind_rows(list(df, df2))






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 at 22:34









André.B

357




357












  • The above code can be fed multiple df/tibbles simultaneously without the use of a do.call loop as well. As below the names need to be constant between dataframes for them to line up.
    – André.B
    Nov 19 at 22:36


















  • The above code can be fed multiple df/tibbles simultaneously without the use of a do.call loop as well. As below the names need to be constant between dataframes for them to line up.
    – André.B
    Nov 19 at 22:36
















The above code can be fed multiple df/tibbles simultaneously without the use of a do.call loop as well. As below the names need to be constant between dataframes for them to line up.
– André.B
Nov 19 at 22:36




The above code can be fed multiple df/tibbles simultaneously without the use of a do.call loop as well. As below the names need to be constant between dataframes for them to line up.
– André.B
Nov 19 at 22:36



Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python