0

I have a list of patients and the hospitals where they are treated. However one of the hospitals is listed as being in another state so I wanna change it

I'm trying to do it like this:

db <- ifelse(db$hospital=="NYC Hospital", db$State=="New York"),)

However it says I'm missing the NO argument. How can I get around this?

r2evans
  • 108,754
  • 5
  • 72
  • 122
mabj4815
  • 5
  • 2
  • A couple of things wrong here. (1) You are replacing the whole `data.frame` object (inferring) with a vector. This is not incorrect syntax, but seems suspect. (2) The error cannot be more clear: the `no=` argument to the `ifelse` function is **required**, and you are not providing it. The `ifelse` function, if it "spoke", says *"when the `test=` is true then return `yes=`, otherwise return `no=`"* (for each condition in the `test=` vector, which should be the same length as `yes=`/`no=`). – r2evans Jul 29 '20 at 20:14
  • 1
    Please provide sample data with `dput(x)` where `x` is a *small* sample of your `db` variable that includes that hospital (positive test) and other hospitals (negative test). Refs: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. – r2evans Jul 29 '20 at 20:15

1 Answers1

0

Just leave it the same when the answer is NO:

db$State <- ifelse(db$hospital == "NYC Hospital", "New York", db$State)

Next time try using the code syntax

Fernando
  • 116
  • 8