0

I have a data table called DT in R and I have a subtable called VIDEOSEL. I want to create a new table called NDT that contains the rows of DT only if they appear in VIDEOSEL.

For example: DT=

NAME UNID
54   4
37   7
122  8

VIDEOSEL=

NAME UNID
54   14

NDT=

NAME UNID
54   4

I have this code

NDT<-NULL
 for (i in 1:dim(DT)[1]){
   mat<-is.na(match(DT$NAME[i],VIDEOSEL$NAME))
   if(mat)
     {
       NDT<-rbind(NDT,DT[i,])
  }
}

The problem is that it is terribly slow because DT has 150000 elements. How can I improve the peformance?

Thanks a lot

  • lookup `merge`. many answers to similar questions here – Chris Oct 08 '15 at 16:47
  • See this answer http://stackoverflow.com/questions/32917934/how-to-find-common-rows-between-two-dataframe-in-r/32918022#32918022 – R. Schifini Oct 08 '15 at 16:48
  • If you are open to installing a package, you can take the `intersect` of two data.frames after loading a package called dplyr. – Frank Oct 08 '15 at 16:55

0 Answers0