根据另一列替换一列中的NA值

时间:2012-08-24 22:36:29

标签: r missing-data

 Id         authId          sessionId                         
139 "56763313.wrpy" "4233a31b52f92c6fe8af4f04f2116657"
123 "221156400"     "ae04ddacadaa3429ca77dab674a008bf"
126 "221156400"     "ae04ddacadaa3429ca77dab674a008bf"
144 "221156400"     "ae04ddacadaa3429ca77dab674a008bf"
143 "221156400"     "ae04ddacadaa3429ca77dab674a008bf"
118 NA              "ae04ddacadaa3429ca77dab674a008bf"
121 NA              "ae04ddacadaa3429ca77dab674a008bf"
122 NA              "ae04ddacadaa3429ca77dab674a008bf"
75  "5676614888888" "ca673b5e60a6f70963bf3017e3cb0780"
276 "56711325.cc79" "f6075188c0f479d7a423744f6c8655b3"
256 "56711325.cc79" "f6075188c0f479d7a423744f6c8655b3"
275 "56711325.cc79" "f6075188c0f479d7a423744f6c8655b3"
152 NA              "f6075188c0f479d7a423744f6c8655b3"
158 NA              "f6075188c0f479d7a423744f6c8655b3"
28  "221124184"     "fc71064548bb35d05293bd67d55f1693"
31  "221124184"     "fc71064548bb35d05293bd67d55f1693"

我想根据authId填写遗失的sessionId。我试图在不使用循环的情况下这样做。例如:

143 "221156400"     "ae04ddacadaa3429ca77dab674a008bf"
118 "221156400"     "ae04ddacadaa3429ca77dab674a008bf"

1 个答案:

答案 0 :(得分:3)

首先创建一个包含authIdsessionId唯一组合的数据框。然后找到sessionId的任何authId的{​​{1}}。使用唯一表格查找与NA相关联的sessionId

authId