How to delete column by condition

antibiotic_type | route
ciprofloxacin | IV
ciprofloxacin | PO
doxycycline | IV
doxycycline | PO
penicillin | IV
penicillin | IV
doxycycline | PO
doxycycline | PO
penicillin | IV
penicillin | IV

  • I want to delete "PO" from the whole column.

Hi @Bishwaraj_Deo, could you put a reproducible example for understand better the situation:

d_i_b_w <- df

antibiotic_type <- ciprofloxacin, ciprofloxacin, doxycycline, doxycycline, penicillin, penicillin
route <- IV, PO, IV, PO, IV, IV

You need something like this?

example_data <- data.frame(antibiotic_type = c("ciprofloxacin", "ciprofloxacin", "doxycycline", "doxycycline", "penicillin", "penicillin", "doxycycline", "doxycycline", "penicillin", "penicillin"), 
                   route = c("IV", "PO", "IV", "PO", "IV", "IV", "PO", "PO", "IV", "IV"))
  example_data
#>    antibiotic_type route
#> 1    ciprofloxacin    IV
#> 2    ciprofloxacin    PO
#> 3      doxycycline    IV
#> 4      doxycycline    PO
#> 5       penicillin    IV
#> 6       penicillin    IV
#> 7      doxycycline    PO
#> 8      doxycycline    PO
#> 9       penicillin    IV
#> 10      penicillin    IV
  
  example_data$route <- ifelse(example_data$route == "PO", "", example_data$route)
  
  example_data
#>    antibiotic_type route
#> 1    ciprofloxacin    IV
#> 2    ciprofloxacin      
#> 3      doxycycline    IV
#> 4      doxycycline      
#> 5       penicillin    IV
#> 6       penicillin    IV
#> 7      doxycycline      
#> 8      doxycycline      
#> 9       penicillin    IV
#> 10      penicillin    IV

Created on 2023-05-10 by the reprex package (v2.0.1)

This topic was automatically closed 21 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.