R - Add a column of data to an existing column in a dataframe [duplicate]
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
r dataframe
marked as duplicate by M-M, Rui Barradas, Ronak Shah
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.
add a comment |
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
r dataframe
marked as duplicate by M-M, Rui Barradas, Ronak Shah
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/…
– M-M
Nov 19 at 22:30
add a comment |
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
r dataframe
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
r dataframe
asked Nov 19 at 22:21
Myco
297
297
marked as duplicate by M-M, Rui Barradas, Ronak Shah
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 M-M, Rui Barradas, Ronak Shah
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/…
– M-M
Nov 19 at 22:30
add a comment |
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/…
– M-M
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/…
– M-M
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/…
– M-M
Nov 19 at 22:30
add a comment |
2 Answers
2
active
oldest
votes
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
1
Please provide dupes instead of posting answers, when applicable.
– M-M
Nov 19 at 22:28
add a comment |
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))
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
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
1
Please provide dupes instead of posting answers, when applicable.
– M-M
Nov 19 at 22:28
add a comment |
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
1
Please provide dupes instead of posting answers, when applicable.
– M-M
Nov 19 at 22:28
add a comment |
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
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
answered Nov 19 at 22:25
SmitM
1,0961111
1,0961111
1
Please provide dupes instead of posting answers, when applicable.
– M-M
Nov 19 at 22:28
add a comment |
1
Please provide dupes instead of posting answers, when applicable.
– M-M
Nov 19 at 22:28
1
1
Please provide dupes instead of posting answers, when applicable.
– M-M
Nov 19 at 22:28
Please provide dupes instead of posting answers, when applicable.
– M-M
Nov 19 at 22:28
add a comment |
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))
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
add a comment |
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))
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
add a comment |
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))
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))
answered Nov 19 at 22:34
André.B
528
528
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
add a comment |
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
add a comment |
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/…
– M-M
Nov 19 at 22:30