samedi 11 avril 2020

R: How to create a specific loop and ifelse statements for my data set. (DATA SET ATTACHED)

I am new to R and I would like to seek your advice on the type of code that could assist me in performing a complex task. I have a set of variables that contain pass or fail values. Base on these values, the test function should accomplish the tasks written below:

  1. Check if Normal == Fail, if true create a new column called test which inserts "Fail" into the column for that particular case.

  2. If normal == Fail, is false, check from PD to SA == Fail. If true, inserting "Fail" into the column named test that was created in step 1.

  3. If PD to SA == Fail is false, insert "pass" into the column named test that was created in step 1.

  4. Any NAs in a particular case should be skipped.

Ideally, the table at the end should look like this: Example 1

As you can see from example 1, Even though normal == pass, because TH == Fail, the end result of the test column was "fail".

In Example 2, All values from normal to SA == pass, the end result of the test column == "Pass".

Lastly in Example 3, because normal == "Fail", the end result of the test column == "Fail".

I have been trying to create this function and iterate it through the 2000 cases in my dataset. But none has worked. Any help will be greatly appreciated. I have attached the link to my dataset in the question for reference. https://drive.google.com/file/d/1nd0c99kuMiUdjhiKxNHK-j5TY9de9vbX/view?usp=sharing

Aucun commentaire:

Enregistrer un commentaire