Merge rows in a dataframe where the rows are disjoint and contain NAs

You can use aggregate. Assuming that you want to merge rows with identical values in column name: aggregate(x=DF[c(“v1″,”v2″,”v3″,”v4”)], by=list(name=DF$name), min, na.rm = TRUE) name v1 v2 v3 v4 1 Yemen 4 2 3 5 This is like the SQL SELECT name, min(v1) GROUP BY name. The min function is arbitrary, you could also use max … Read more