Hello,
Sorry, there's a bug in my first reply. Corrected:
fun <- function(x, y){
df3 <- cbind(x, y[setdiff(names(y), names(x))])
df3[order(names(df3))]
}
fun(df1, df2)
Rui Barradas
Em 07-02-2013 19:16, Rui Barradas escreveu:
Hello,
The following function will give what you s
Hello,
The following function will give what you seem to want.
fun <- function(x, y){
df3 <- x
df3 <- cbind(df3, df2[setdiff(names(y), names(x))])
df3[order(names(df3))]
}
fun(df1, df3)
Hope this helps,
Rui Barradas
Em 07-02-2013 18:36, Anika Masters escreveu:
#I
, 2013 12:36 PM
Subject: [R] combining dataframes into single df with all columns
#I have 2 dataframes df1 & df2. Each has a subset of all possible column names.
#How do I combine the 2 tables so that they contain all column names?
data1 <- c('2','3', '6',
#I have 2 dataframes df1 & df2. Each has a subset of all possible column names.
#How do I combine the 2 tables so that they contain all column names?
data1 <- c('2','3', '6', '8' , '9')
data2 <- c('1', '2', '3', '6')
df1 <- data.frame(matrix(data=NA, nrow=1, ncol=length(data1),
dimnames=list(NULL
#I have 2 dataframes df1 & df2. Each has a subset of all possible column
names. #How do I combine the 2 tables so that they contain all column
names? data1 <- c('2','3', '6', '8' , '9') data2 <- c('1', '2',
'3', '6') df1
<- data.frame(matrix(data=NA, nrow=1, ncol=length(data1),
dimnames=lis
5 matches
Mail list logo