[R] Merge and replace data
Rui Barradas
ru|pb@rr@d@@ @end|ng |rom @@po@pt
Tue Sep 5 12:39:38 CEST 2023
À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 value in the column which is non zero..
> I tried append and merge but fail to get what I want.
>
Hello,
That's a case for ?pmax:
x1 <- c(116,0,115,137,127,0,0)
x2 <- c(0,159,0,0,0,159,127)
pmax(x1, x2)
#> [1] 116 159 115 137 127 159 127
Hope this helps,
Rui Barradas
More information about the R-help
mailing list