This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to subset same data from 2 data.frame

I am working on 2 data.frame and i want to subset same datas. I tried to use merge function but it gave me error like <0 rows> (or 0-length row.names).

x= data.frame(
  ID = c("abc", "def", "genone", "gentwo", "unc"),
  a = c("kerem", "fuat", "sinan", "suat", "anp"),
  b = c("lml", "jhkj", "jk", "kjhk", "mkmkk"),
  c = c("eee", "ttt", "hhh", "mmm", "kkk")
)

y= data.frame(
  ID = c("genone","gentwo","genthree","genfourth","genfive"),
  a = c("fuat", "suat", "mert", "mehmet", "ali"),
  b = c("irem", "melisa", "cansu", "aslı", "fatma"),
  c = c("aaa", "bbb", "ccc", "ddd", "fff")
)
merge(x,y)

I wrote these but it gave same error. <0 rows> (or 0-length row.names).

data.frame
> merge(x,y, by = "ID")

      ID   a.x  b.x c.x  a.y    b.y c.y
1 genone sinan   jk hhh fuat   irem aaa
2 gentwo  suat kjhk mmm suat melisa bbb


> lapply(setNames(names(x),names(x)), function (a) merge(x,y, by = a))

$ID
      ID   a.x  b.x c.x  a.y    b.y c.y
1 genone sinan   jk hhh fuat   irem aaa
2 gentwo  suat kjhk mmm suat melisa bbb

$a
     a   ID.x  b.x c.x   ID.y    b.y c.y
1 fuat    def jhkj ttt genone   irem aaa
2 suat gentwo kjhk mmm gentwo melisa bbb

$b
[1] b    ID.x a.x  c.x  ID.y a.y  c.y 
<0 rows> (or 0-length row.names)

$c
[1] c    ID.x a.x  b.x  ID.y a.y  b.y 
<0 rows> (or 0-length row.names)

0 answers

No answers yet.

Log in to answer this question.