creating a new column by filtering the data

create a new column "any_iv_in_bcx_window" and fill it with TRUE, if "route" = IV and "total_variables" = 1 , and other with 0 as FALSE.

A tibble: 6 × 8

...1 patient_id antibiotic_type route last_administration_day blood_culture_day

1 - 1 -ciprofloxacin - IV - 18 - 3
2 - 1 -ciprofloxacin - IV - 18 - 13
3 - 1 -doxycycline -IV - 16 - 3
4 - 1 -doxycycline -PO - 16 - 13
5 - 1 -penicillin -IV - 15 - 3
6 - 1- penicillin -PO - 15 - 13

Drugs_In_BCX_Window total_variables

15 - 1
5 - 0
13 - 0
3 - 0
12 - 1
6 - 1

Try

your_tibble |>
  dplyr::mutate(any_iv_in_bcx_window = route == "IV" & total_variables == 1)

I would suggest putting your code or text output between triple backticks, like this

```
your tibble
```

which makes it much easier to read.

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.