How to use R ifelse statements with multiple conditions?
<p>I am new to R but am excited to learn it and I thought this might be a good opportunity. 
I have two measurements of salinity (uS and mS.m_1.5). I have created 3 classes (1, 2, 3) for each measurement type (uSClass and mS.m_1.5Class) based on their values. For many of the observations, I only have 1 measurement type.
I want to create a new class (SClass) based on these two classes. </p>

<p>Any observation of uSClass = 1 and mS.m_1.5Class = 1, should be SClass 1.</p>

<p>Any observation of uSClass = 1 and mS.m_1.5Class = NA, should be SClass 1.</p>

<p>Any observation of uSClass = NA and mS.m_1.5Class = 1, should be SClass 1. etc...</p>

<p>Any observation with conflicting classes (ex. uSClass = 1 and mS.m_1.5Class = 2) should not be assigned a class (NA). 
This is my code:</p>

<pre><code>    std$SClass &lt;- ifelse(std$uSClass == 1 &amp; std$mS.m_1.5Class == 1, 1, 
                     ifelse(std$uSClass == 1 &amp; is.na(std$mS.m_1.5Class), 1,
                        ifelse(is.na(std$uSClass) &amp; std$mS.m_1.5Class == 1, 1,
                  ifelse(std$uSClass == 2 &amp; std$mS.m_1.5Class == 2, 2,
                     ifelse(std$uSClass == 2 &amp; is.na(std$mS.m_1.5Class), 2,
                        ifelse(is.na(std$uSClass) &amp; std$mS.m_1.5Class == 2, 2,
                  ifelse(std$uSClass == 3 &amp; std$mS.m_1.5Class == 3, 3,
                     ifelse(std$uSClass == 3 &amp; is.na(std$mS.m_1.5Class), 3,
                        ifelse(is.na(std$uSClass) &amp; std$mS.m_1.5Class == 3, 3, NA)))))))))
</code></pre>

<p>It makes logical sense to me but it must not be correct. The only classifications that work are those where both uSClass and mS.m_1.5Class have values. If I run the entire code, most observations are assigned NA. I have tried a couple other methods incorporating | operators but those have not worked either.
Your help is appreciated!</p>