Re: [R] Problem merging data frames and duplicates

2015-05-27 Thread William Michels
Notes: 1. You can get output for all states (alphabetically) by pre-merging data with states.abb: a1 <- merge(state.abb, x, by= 1, all.x=T) b1 <- merge(state.abb, y, by= 1, all.x=T) colnames(a1) <- c("state", "locus") colnames(b1) <- c("state", "locus") by.states1(a1,b1) 2. In my previous post (

Re: [R] Problem merging data frames and duplicates

2015-05-27 Thread Frank Burbrink
Interesting solutions. Thanks guys! On Wed, May 27, 2015 at 9:27 AM, William Michels wrote: > Hi Frank! > > Ok, bind columns together in a state-wise fashion, allowing for state > duplicates. Below (maybe cheesy) uses the state abbreviations > "state.abb" in the datasets package. Also uses two f

Re: [R] Problem merging data frames and duplicates

2015-05-27 Thread William Michels
Hi Frank! Ok, bind columns together in a state-wise fashion, allowing for state duplicates. Below (maybe cheesy) uses the state abbreviations "state.abb" in the datasets package. Also uses two functions "rbind.na" and "cbind.na", available from Andrej-Nikolai Spiess' website at: http://www.dr-spi

Re: [R] Problem merging data frames and duplicates

2015-05-27 Thread Frank Burbrink
I have figured out a cheesy work around since these problems have to do with not having unique identifiers for the States: 1) Append a unique identifier to each state such that both AR becomes ARa and ARb 2) run the normal merge(x,y,by=1, all=T) 3) Use subst to cut the appended identifiers. While

Re: [R] Problem merging data frames and duplicates

2015-05-27 Thread Frank Burbrink
Thanks Bill, However, unique(merge(x, y, by = 1, all=T)) is giving me: state locus.x locus.y 1 AR 5 2 2 AR 5 3 3 AR 6 2 4 AR 6 3 5 IL 1 1 9 LA 2 NA 11MS 3 NA 12MS 4 NA 1

Re: [R] Problem merging data frames and duplicates

2015-05-27 Thread John Kane
ect.org > Subject: [R] Problem merging data frames and duplicates > > Hello All, > > I am attempting to merge two data frames that naturally contain duplicate > entries, however when using either merge or dMerge I get even more > duplicates. > > For example: > >

Re: [R] Problem merging data frames and duplicates

2015-05-27 Thread William Michels
Hi Frank, It looks like you're very close. I think you want: unique(merge(x, y, by = 1, all=T)) Gabor Grothendieck's sqldf package is very useful if you're more comfortable with SQL-type syntax, see: https://github.com/ggrothendieck/sqldf Best Regards, William (Bill) Michels, Ph.D. On Tue,

[R] Problem merging data frames and duplicates

2015-05-26 Thread Frank Burbrink
Hello All, I am attempting to merge two data frames that naturally contain duplicate entries, however when using either merge or dMerge I get even more duplicates. For example: data.frame(state=c("IL", "IL", "LA","LA", "MS","MS", "AR", "AR"), locus=c(1,1,2,2,3,4,5,6))->x data.frame(state=c("IL"