Re: [R] Merge and replace data

2023-09-07 Thread Richard O'Keefe
I'm a little confused, because the sample code does something that none of the suggestions does. x1 <- c(116,0,115,137,127,0,0) x2 <- c(0,159,0,0,0,159,127) [You] want : xx <- c(116,115,137,127,159, 127) Assuming that there should have been two copies of 159 in xx, this is xx <- c(x1[x1 != 0],

Re: [R] Merge and replace data

2023-09-05 Thread roslinazairimah zakaria
Thank you for the general code. Really appreciate it. On Tue, Sep 5, 2023 at 7:59 PM Eric Berger wrote: > As Duncan points out, ifelse() provides a more general approach than > the specific pmax(). > > Even more generally, you might want to consider the apply() function > (and its relatives

Re: [R] Merge and replace data

2023-09-05 Thread roslinazairimah zakaria
Thank you for the general code. Really appreciate it. On Tue, Sep 5, 2023 at 7:45 PM Duncan Murdoch wrote: > On 05/09/2023 4:55 a.m., roslinazairimah zakaria wrote: > > Hi all, > > > > I have these data > > > > x1 <- c(116,0,115,137,127,0,0) > > x2 <- c(0,159,0,0,0,159,127) > > > > I want : xx

Re: [R] Merge and replace data

2023-09-05 Thread Eric Berger
As Duncan points out, ifelse() provides a more general approach than the specific pmax(). Even more generally, you might want to consider the apply() function (and its relatives sapply(), lapply(), ...) For example apply(cbind(x1,x2), MAR=1, max) In the above statement, x1 and x2 are combined

Re: [R] Merge and replace data

2023-09-05 Thread Duncan Murdoch
On 05/09/2023 4:55 a.m., roslinazairimah zakaria wrote: Hi all, I have these data x1 <- c(116,0,115,137,127,0,0) x2 <- c(0,159,0,0,0,159,127) I want : xx <- c(116,115,137,127,159, 127) I would like to merge these data into one column. Whenever the data is '0' it will be replaced by the value

Re: [R] Merge and replace data

2023-09-05 Thread roslinazairimah zakaria
Thank you very much for your help. On Tue, Sep 5, 2023 at 6:39 PM Rui Barradas wrote: > Às 09:55 de 05/09/2023, roslinazairimah zakaria escreveu: > > Hi all, > > > > I have these data > > > > x1 <- c(116,0,115,137,127,0,0) > > x2 <- c(0,159,0,0,0,159,127) > > > > I want : xx <-

Re: [R] Merge and replace data

2023-09-05 Thread roslinazairimah zakaria
Thank you very much for your help. On Tue, Sep 5, 2023 at 6:12 PM Eric Berger wrote: > xx <- pmax(x1,x2) > > On Tue, Sep 5, 2023 at 11:56 AM roslinazairimah zakaria > wrote: > > > > Hi all, > > > > I have these data > > > > x1 <- c(116,0,115,137,127,0,0) > > x2 <- c(0,159,0,0,0,159,127) > > >

Re: [R] Merge and replace data

2023-09-05 Thread Rui Barradas
Às 09:55 de 05/09/2023, roslinazairimah zakaria escreveu: Hi all, I have these data x1 <- c(116,0,115,137,127,0,0) x2 <- c(0,159,0,0,0,159,127) I want : xx <- c(116,115,137,127,159, 127) I would like to merge these data into one column. Whenever the data is '0' it will be replaced by the

Re: [R] Merge and replace data

2023-09-05 Thread Eric Berger
xx <- pmax(x1,x2) On Tue, Sep 5, 2023 at 11:56 AM roslinazairimah zakaria wrote: > > Hi all, > > I have these data > > x1 <- c(116,0,115,137,127,0,0) > x2 <- c(0,159,0,0,0,159,127) > > I want : xx <- c(116,115,137,127,159, 127) > > I would like to merge these data into one column. Whenever the

[R] Merge and replace data

2023-09-05 Thread roslinazairimah zakaria
Hi all, I have these data x1 <- c(116,0,115,137,127,0,0) x2 <- c(0,159,0,0,0,159,127) I want : xx <- c(116,115,137,127,159, 127) I would like to merge these data into one column. Whenever the data is '0' it will be replaced by the value in the column which is non zero.. I tried append and