How to rbind only the common columns of two data sets

后端 未结 3 810

I have 2 data frames with different number of columns each. Some of the columns are common between the 2 data frames. How can i rbind only the common columns of the two data

3条回答
  •  不要未来只要你来
    2021-01-12 03:06

    Here is my solution hope i got your question right

    df1 <- data.frame(a=rnorm(100), b=rnorm(100), not=rnorm(100))
    df2 <- data.frame(a=rnorm(100), b=rnorm(100))
    
    bind1 <- bind1 <- df1[, names(df1) %in% names(df2)]
    bind2 <- bind1 <- df1[, names(df2) %in% names(df1)]
    
    rbind(bind1, bind2)
    

提交回复
热议问题