Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否有更短的方法来按顺序按键返回值,由键的元素给出?
vars<-c("a"=1,"b"=2) key<-c("b","a") ret<-c() for(k in key) ret<-c(ret,vars[names(vars) %in% k]) ret
相信你只是想要vars[key]。
vars[key]
我想intersect可能对你有用...
intersect
vars[ intersect(key,names(vars)) ] #b a #2 1