[英]Vectorized version of which in R?
I want to run this loop: 我想运行此循环:
householdnums=numeric()
for(i in 1:length(households)){
hh = households[i]
householdnums = c(householdnums,which(hhlist==hh))
}
Where households and hhlist is a large vector. 家庭和hhlist是很大的载体。 The problem is that households has duplicates of elements in hhlist, and I need to preserve the ordering.
问题是住户在hhlist中有重复的元素,我需要保留顺序。 For example.
例如。
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
匹配:例如匹配(家庭,hhlist)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.