Is there a way to create Stata's _merge indicator variable with R's merge()?

前端 未结 3 1479
再見小時候
再見小時候 2021-01-18 21:18

Stata automatically creates a variable called \"_merge\" indicating the matched variables in both datasets after merge. Is there a way to get such variable generated by R\'s

3条回答
  •  被撕碎了的回忆
    2021-01-18 21:45

    The possible values of _merge in Stata are (note merge can also have values 4 and 5)

                  1       master             observation appeared in master only
                  2       using              observation appeared in using only
                  3       match              observation appeared in both
    

    In R, you can do that by entering the argument as either all=TRUE or all.x=TRUE or all.y=TRUE

    e.g.,

    merge(x, y, by = intersect(names(x), names(y)),by.x = by, by.y = by, all = TRUE)
     merge(x, y, by = intersect(names(x), names(y)),by.x = by, by.y = by, all.x = TRUE)
     merge(x, y, by = intersect(names(x), names(y)),by.x = by, by.y = by, all.y = TRUE)
    

提交回复
热议问题