[R] cleanup/replacing a value on condition of another value

Dr Eberhard W Lisse no@p@m @end|ng |rom ||@@e@NA
Mon Oct 25 19:26:03 CEST 2021


Thank you very much,

'which' does the trick :-)-O

greetings, el

On 2021-10-25 19:06 , Rui Barradas wrote:
> Hello,
> 
> Here is a pipe to replace based on the composite condition.
> It uses ?base::replace with an integer index vector.
> 
[...]
> library(dplyr)
> 
> data(coronavirus, package = "coronavirus")
> 
> coronavirus %>%
[...]
>    mutate(cases = replace(cases,
>                           which(country == 'Namibia' &
>                                   date == '2021-10-23' &
>                                   cases == 357), NA)
>    )
[...]
> 
> Hope this helps,
> 
> Rui Barradas
[...]



More information about the R-help mailing list