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

2021-10-26 Thread Dr Eberhard W Lisse
Thanks. Your method mutate( cases = ifelse( country == 'Namibia' & type == 'confirmed' & date == '2021-10-23' & cases == 357, NA, cases ) ) works, as does Rui's mutate( cases = replace( cases,

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

2021-10-25 Thread Avi Gross via R-help
help@r-project.org Subject: Re: [R] cleanup/replacing a value on condition of another value Rui, that works for me too, but is not what I need to do. I want to make the 'cases' value for this particular country AND this particular date AND this particular type AND this particular value (

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

2021-10-25 Thread Dr Eberhard W Lisse
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 =

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

2021-10-25 Thread Rui Barradas
Hello, Here is a pipe to replace based on the composite condition. It uses ?base::replace with an integer index vector. In the end, filter is meant to show the changed value in context, remove it and assign the data.frame or tibble back to the input to change the original. library(dplyr)

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

2021-10-25 Thread Dr Eberhard W Lisse
Rui, that works for me too, but is not what I need to do. I want to make the 'cases' value for this particular country AND this particular date AND this particular type AND this particular value (ie ALL conditions must be fulfilled) become NA so that the tibble would change from [...]

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

2021-10-25 Thread Rui Barradas
Hello, The following works with me. library(coronavirus) library(dplyr) data(coronavirus, package = "coronavirus") #update_dataset(silence = FALSE) coronavirus %>% select(country, date, type, cases) %>% filter( country == 'Namibia', date == '2021-10-23', cases == 357 )

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

2021-10-25 Thread Eric Berger
The tibble shows the 'date' column as type date but you are comparing io a string. Perhaps replace that piece by date == as.Date("2021-10-23") Not tested. HTH, Eric On Mon, Oct 25, 2021 at 2:26 PM Dr Eberhard W Lisse wrote: > > Hi, > > I have data from JHU via the 'coronavirus' package which

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

2021-10-25 Thread Dr Eberhard W Lisse
Hi, I have data from JHU via the 'coronavirus' package which has a value for the confirmed cases for 2021-10-23 which differs drastically (357) from what is reported in country (23). # A tibble: 962 × 4 country date type cases 1