thanks Henrique , it did work with a slight modif subset(merge(X, Y, by.x = 'groups', by.y = 1, all = TRUE), var2<var3). -- View this message in context: http://r.789695.n4.nabble.com/removing-rows-from-a-matrix-using-condition-within-groups-tp3004132p3005899.html Sent from the R help mailing list archive at Nabble.com.