First off, let me apologize for the elementary question. I'm obviously a novice. Here's a stripped version of my problem. March foreign id = 1234, my id = 1 foreign id = 1235, my id = 2 foreign id = 1236, my id = 3 So we are adding new people for April, and things don't necessarily come in order: April foreign id = 1236 foreign id = 5000 foreign id = 1234 foreign id = 1235 foreign id = 7777 I need to create a vector of my own IDs. "1236" would obviously need to be translated to my id = 3 but I would also need to incrementally add a new "my id" for our new entry, so I'd want foreign id 5000 to be translated to my id 4, and foreign id = 7777 to be translated into my id 5. Please help! I have puzzled over this for far longer than I'd care to admit, late into last night and now all morning. -- View this message in context: http://r.789695.n4.nabble.com/Converting-ID-Numbers-to-Unique-ID-Number-tp3827281p3827281.html Sent from the R help mailing list archive at Nabble.com.
A reproducible example would be useful, as yours isn't entirely clear. But maybe something like this? id.info <- data.frame(foreign=sort(unique(foreign.id)), local=1:length(unique(foreign.id))) and then use merge() to combine that with your actual data. Sarah On Tue, Sep 20, 2011 at 11:50 AM, Totally Inept <joe.kramer at forwardhealthgroup.com> wrote:> First off, let me apologize for the elementary question. I'm obviously a > novice. > > Here's a stripped version of my problem. > > March > foreign id = 1234, my id = 1 > foreign id = 1235, my id = 2 > foreign id = 1236, my id = 3 > > So we are adding new people for April, and things don't necessarily come in > order: > > April > foreign id = 1236 > foreign id = 5000 > foreign id = 1234 > foreign id = 1235 > foreign id = 7777 > > I need to create a vector of my own IDs. "1236" would obviously need to be > translated to my id = 3 but I would also need to incrementally add a new "my > id" for our new entry, so I'd want foreign id 5000 to be translated to my id > 4, and foreign id = 7777 to be translated into my id 5. > > Please help! I have puzzled over this for far longer than I'd care to admit, > late into last night and now all morning. >-- Sarah Goslee http://www.functionaldiversity.org
something like this should work:> oldIDs <- c(1234, 1235, 1236) > newIDs <- c(5000, 1234, 7000, 1236) > # really new ones -- don't match the old ones > (reallyNew <- setdiff(newIDs, oldIDs))[1] 5000 7000> # assign these back to the oldIDs for the next month > (oldIDs <- c(oldIDs, reallyNew))[1] 1234 1235 1236 5000 7000>On Tue, Sep 20, 2011 at 11:50 AM, Totally Inept <joe.kramer at forwardhealthgroup.com> wrote:> First off, let me apologize for the elementary question. I'm obviously a > novice. > > Here's a stripped version of my problem. > > March > foreign id = 1234, my id = 1 > foreign id = 1235, my id = 2 > foreign id = 1236, my id = 3 > > So we are adding new people for April, and things don't necessarily come in > order: > > April > foreign id = 1236 > foreign id = 5000 > foreign id = 1234 > foreign id = 1235 > foreign id = 7777 > > I need to create a vector of my own IDs. "1236" would obviously need to be > translated to my id = 3 but I would also need to incrementally add a new "my > id" for our new entry, so I'd want foreign id 5000 to be translated to my id > 4, and foreign id = 7777 to be translated into my id 5. > > Please help! I have puzzled over this for far longer than I'd care to admit, > late into last night and now all morning. > > -- > View this message in context: http://r.789695.n4.nabble.com/Converting-ID-Numbers-to-Unique-ID-Number-tp3827281p3827281.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve?