[英]How Do I add column to data frame that uses a mathematical equation with variables from the existing columns?
[英]How do I add observations to an existing data frame column?
選項是分配
n <- nrow(x)
x[n + seq_along(y), ] <- y
x
# a b c
#1 2 5 6
#2 3 1 4
#3 1 2 7
#4 4 4 4
#5 5 5 5
#6 8 8 8
#7 8 8 8
另一種選擇是replicate
'y'和rbind
rbind(x, `colnames<-`(replicate(ncol(x), y), names(x)))
可以做:
as.data.frame(sapply(x,
function(z)
append(z,y)))
a b c
1 2 5 6
2 3 1 4
3 1 2 7
4 4 4 4
5 5 5 5
6 8 8 8
7 8 8 8
x[(nrow(x)+1):(nrow(x)+length(y)),] <- y
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.