【发布时间】:2015-03-22 03:48:36
【问题描述】:
我想运行这个循环:
householdnums=numeric()
for(i in 1:length(households)){
hh = households[i]
householdnums = c(householdnums,which(hhlist==hh))
}
其中户和 hhlist 是一个大向量。问题是家庭在 hhlist 中有重复的元素,我需要保留顺序。例如。
hhlist = c(1,2,3,4,5,6, 8)
households = c(1,2,1,1,4,5,6,8)
householdnums should be:
householdnums
[1] 1 2 1 1 4 6 6 7
【问题讨论】:
-
我不明白你的家庭人数应该如何
1 2 1 1 4 6 6 7 -
你想要
match: 例如match(households, hhlist) -
哎呀,我的头! :p OP,我认为我们需要澄清你在这里问/做什么!谢谢
-
which已矢量化。 -
匹配正是我想要的!你能发帖吗,我会最好的回答你