Using one data.frame to update another

后端 未结 7 455

Given 2 data frames that are identical in terms of column names/datatypes, where some columns uniquely identify the rows, is there an efficient function/method for one data.

7条回答
  •  鱼传尺愫
    2020-12-20 12:52

    Here is an approach using the digest package.

    library(digest)
    # generate keys for each row using the md5 checksum based on first two columns
    check1 <- apply(original[,1:2], 1, digest)
    check2 <- apply(replacement[,1:2], 1, digest)
    
    # set goal to original and replace rows in replacement
    goal <- original
    goal[check1 %in% check2,] <- replacement
    

提交回复
热议问题