I have a data frame with two columns relevant to the task at hand; one is numeric, and the other contains single letter codes to denote things about the data; i.e., below method detection limit, above the highest calibration standard, etc.
Some of these codes require the performance of a mathematical operation to correct for things within the data, and I was wondering what to do in order to edit a column based on the values in another.
I'm assuming I'll need some kind of loop, and it may be easier to create a new column of calculated values than to edit the existing one. In that case, I'll need an else clause to just copy the plain number over when no manipulation is required.
I'm still relatively new to R, so mainly I need help coming up with the syntax for the loop as well as what type of loop (I was assuming an 'if' with lots of 'else', but that may be wrong).
Here is an example of my dataframe:
wbid STA year month day time depth param mastercode result rcode xcode lab mdl pql dunits ds
1 2749A 21FLA 20020137 2014 7 1 1125 0.3 410 ALK 26.000 6 0.650000000 2.500000000 m fs
2 2749A 21FLA 20020137 2014 7 1 1125 0.3 32209 CHLAC 2.300 6 0.690000000 2.100000000 m fs
3 2749A 21FLA 20020137 2014 7 1 1125 0.3 80 COLOR 240.000 6 5.000000000 12.000000000 m fs
4 2749A 21FLA 20020137 2014 7 1 1125 0.3 600 TN 1.704 + 0 fs
5 2749A 21FLA 20020137 2014 7 1 1125 0.3 665 TP 0.170 6 0.005000000 0.050000000 m fs
6 2749A 21FLA 20020137 2014 7 1 1125 0.3 49901 TSS 2.000 I I 6 2.000000000 10.000000000 m fs
Basically, when the columns 'rcode' and/or 'xcode' contain a U, I have to take (result*2)/sqrt(2), so I want to iterate through rcode, xcode, and result and, when necessary, update result (or populate a new column) with the mathematically transformed value, or when it's not U coded, leave the value the same or paste the old one in.
Thanks!