Re: [R] help with merging two dataframes function of "egrep"-like formulas

2018-07-18 Thread Bogdan Tanasa
it looks great, thank you very much Jeff for your time and kind help ! On Wed, Jul 18, 2018 at 7:51 PM, Jeff Newmiller wrote: > The traditional (SQL) way to attack this problem is to make the data > structure simpler so that faster comparisons can be utilized: > > > A <-

Re: [R] help with merging two dataframes function of "egrep"-like formulas

2018-07-18 Thread Jeff Newmiller
The traditional (SQL) way to attack this problem is to make the data structure simpler so that faster comparisons can be utilized: A <- data.frame(z=c("a*b", "c*d", "d*e", "e*f"), t =c(1, 2, 3, 4)) B <- data.frame(z=c("a*b::x*y", "c", "", "g*h"), t =c(1, 2, 3, 4))

Re: [R] help with merging two dataframes function of "egrep"-like formulas

2018-07-18 Thread Bogdan Tanasa
Dear Riley, thank you very much for your help and solution. I got some inspiration from stackoverflow website, and I did use sqldf library. It looks that the formula below works too. Thanks a lot ! sqldf("select B.*, A.* from B left join A on instr(B.z, A.z)") On Wed, Jul 18, 2018 at 3:57

Re: [R] help with merging two dataframes function of "egrep"-like formulas

2018-07-18 Thread Bogdan Tanasa
Thanks a lot ! It looks that I am getting the same results with : B %>% regex_left_join(A, by = c(z = 'z')) On Wed, Jul 18, 2018 at 3:57 PM, Riley Finn wrote: > please may I ask for a piece of advise regarding merging two dataframes : >> A <- data.frame(z=c("a*b", "c*d", "d*e", "e*f"), t =c(1,

[R] help with merging two dataframes function of "egrep"-like formulas

2018-07-18 Thread Bogdan Tanasa
Dear all, please may I ask for a piece of advise regarding merging two dataframes : A <- data.frame(z=c("a*b", "c*d", "d*e", "e*f"), t =c(1, 2, 3, 4)) B <- data.frame(z=c("a*b::x*y", "c", "", "g*h"), t =c(1, 2, 3, 4)) function of the criteria : if "the elements in the 1st column of A could be

Re: [R] Help on merging without a common variable

2012-08-03 Thread Petr PIKAL
Hi OTOH I wonder why cbind gives error as OP told us x - data.frame(x = 1:5) y - data.frame(y = 6:15) merge(x,y) cbind(x,y) Gives different results but without any error. Regards Petr On Thu, Aug 2, 2012 at 4:52 PM, Ayyappa Chaturvedula ayyapp...@gmail.com wrote: Michael, Thank you

[R] Help on merging without a common variable

2012-08-02 Thread Ayyappa Chaturvedula
Dear All, I want to create a dataset for a NONMEM simulation. I have a dataframe with individual PK parameters and want to create a dosing sceinario in a second dataframe. I want to merge them both so that every individiual's PK parameters are combined with the dosing scenario into one. I do not

Re: [R] Help on merging without a common variable

2012-08-02 Thread R. Michael Weylandt
You can merge without a common variable: x - data.frame(x = 1:5) y - data.frame(y = 6:10) merge(x,y) works just fine (for one set of expectations) If you need more help, please do make a reproducible example (as requested of all R-help posts): the instructions here might help

Re: [R] Help on merging without a common variable

2012-08-02 Thread R. Michael Weylandt
On Thu, Aug 2, 2012 at 4:52 PM, Ayyappa Chaturvedula ayyapp...@gmail.com wrote: Michael, Thank you for this , it worked. I was thinking by is a required argument in merge function. Well, it is required in a strict sense, but it has a default value (defaulting to the shared names) so _you_

[R] help with merging 2 data frames

2012-07-11 Thread Dimitri Liakhovitski
Dear R-ers, I feel I am close, but can't get it quite right. Thanks a lot for your help! Dimitri # I have 2 data frames: x-data.frame(a=c(aa,aa,ab,ab,ba,ba,bb,bb),b=c(1:2,1:2,1:2,1:2),d=c(10,20,30,40,50,60,70,80))

Re: [R] help with merging 2 data frames

2012-07-11 Thread Jorge I Velez
Hi Dimitri, Try creating a key for x and y and then merging the result by that variable: x$key - with(x, paste(a, b, sep = /)) y$key - with(y, paste(a2, b, sep = /)) merge(x, y, by = 'key')[, c(2:4, 8:9)] HTH, Jorge.- On Wed, Jul 11, 2012 at 6:28 PM, Dimitri Liakhovitski wrote: Dear R-ers,

Re: [R] help with merging 2 data frames

2012-07-11 Thread Dimitri Liakhovitski
Jorge, thank you! that seems to be working, but unfortunately in real life I have thousands of variables (except for a, a2, a3 and b) so that manually selecting columns (as in c(2:4, 8:9)) would be too difficult... Dimitri On Wed, Jul 11, 2012 at 6:36 PM, Jorge I Velez jorgeivanve...@gmail.com

Re: [R] help with merging 2 data frames

2012-07-11 Thread Mercier Eloi
This should do the trick : colnames(y)[1:2]=c(a,a) y2=rbind(y[,-1], y[,-2]) #duplicating the y matrix so the identifiers are only in 1 column merged = merge(x,y2) merged a b d e1 e2 1 aa 1 10 100 101 2 aa 2 20 200 201 3 ab 1 30 100 101 4 ab 2 40 200 201 5 ba 1 50 300 301 6 ba 2 60 400

Re: [R] help with merging 2 data frames

2012-07-11 Thread Rui Barradas
Hello, About many columns like 'e1' and 'e2' I don't know but with the provided example the following does NOT depend on them, only on 'a', 'b' and 'a2' and 'a3'. z - lapply(c(a2, a3), function(cc) merge(x, y, by.x=c(a, b), by.y=c(cc, b))) z - lapply(seq_along(z), function(i)

Re: [R] help with merging 2 data frames

2012-07-11 Thread Dimitri Liakhovitski
Thanks a lot, everyone for your helpful suggestions! Eloi, this is very elegant - thank you! I did not know 2 columns are allowed to have the same names! Always good to learn something new. Thanks again! Dimitri On Wed, Jul 11, 2012 at 6:58 PM, Mercier Eloi emerc...@chibi.ubc.ca wrote: This

Re: [R] help in merging

2009-12-25 Thread Gabor Grothendieck
Not sure if its guaranteed but this sqlite join does seem to preserve the order of the first data frame. library(sqldf) BOD Time demand 118.3 22 10.3 33 19.0 44 16.0 55 15.6 67 19.8 BODrev - BOD[6:1,]; BODrev Time demand 67 19.8 55 15.6 4

[R] help in merging

2009-12-24 Thread utkarsh . singhal
Hi All, I want to merge two datasets by column ID and I don't want the result to be sorted by ID. I am doing the following: z = merge(x, y, by = ID, sort=F) The result is not sorted by ID. But (as oppose to what I expected) it is not even in the original order of either x or y.

Re: [R] help in merging

2009-12-24 Thread milton ruser
Hi there, You can add a order column on x or y and after use this field to order z. Like z-z[order(z$orderfield),] To generate a order on x or y you can do something like x$xorder-1:nrow(x) cheers milton On Thu, Dec 24, 2009 at 2:26 PM, utkarsh.sing...@global-analytics.comwrote: Hi All,

Re: [R] help in merging

2009-12-24 Thread utkarsh . singhal
the order or what order is it taking when I specified sort=F. Regards Utkarsh Original Message Subject: Re: [R] help in merging From: milton ruser milton.ru...@gmail.com Date: Fri, December 25, 2009 1:38 am To: utkarsh.sing...@global-analytics.com Cc