2021年1月20日星期三

r - append one table to another if they share the same value in a column

df1 <- data.frame(a = c(1:5), b = c(6:10), c=c("df1","df1","df1","df1","df1"))  df2 <- data.frame(a = c(1,3,5,7,9), b = c(16:20), c=c("df2","df2","df2","df2","df2"), d= LETTERS[1:5], e= LETTERS[6:10])    

I would like to create a new table that does following:

  1. stack one table on top of the other only if the value in column a matches (i.e. 1,3,5 only)
  2. show only columns a, b, and c (ignore columns d and e)
  3. in total there should be 6 rows and 3 columns, with rows 1-3 from df1 (a=1,3,5), and rows 4-6 from df2 (a=1,3,5)
https://stackoverflow.com/questions/65819792/r-append-one-table-to-another-if-they-share-the-same-value-in-a-column January 21, 2021 at 09:01AM

没有评论:

发表评论