I used this service several months ago and was very pleased with the response.

I have a dataframe with several thousand lines and to each line I need to apply 
a series of "if else" statements. For each row I need either a value or a 
blank/NA. Below is the series of if else statements I have been trying without 
success to integrate into a function such as "apply".

if (t1.secondstrongest<-13000) {NA} else
if (noise>-13000) {NA} else
if ((abs(value.str1-value.str2))==120) {NA} else
if ((abs(value.str1-value.str2))==180) {NA} else
if ((abs(value.str1-value.str2))==240) {NA} else
if (value.str1 ==300&&value.str2 ==0) {value.str1_adj+ bearingdiff} else
if (value.str1 ==0&&value.str2 ==360) {value.str1_adj+360 - bearingdiff} else
if (value.str2<value.str1) {value.str1_adj-bearingdiff} else
if (value.str2>value.str1) {value.str1_adj+bearingdiff}


Below is an example of the dataframe

t1.secondstrongest         Ant_test              value.str1            
value.str1_adj                   value.str2            value.str2_adj           
        Noise                    bearingdiff
1              -10682                                  60                       
    240                         242                                         180 
                                        182                         -12344      
             11.23
2              -11154                                  240                      
   0                              2                                             
 240                                         242                         -13444 
                  27.23
3              -10930                                   300                     
   0                              2                                             
 300                                         302                         -14022 
                  27.55
4              -10997                                   240                     
    300                        302                                         60   
                                        62                           -13456     
              14.23
5              -11244                                  180                      
    180                        182                                         0    
                                          2                              -14209 
                  25.22
6              -12744                                    60                     
     180                        182                                         240 
                                        242                         -14134      
             8.13

The answer to the examples should be...

1                     NA

2                     NA

3                     334.45

4                     NA

5                     NA

6                     190.13


THANKS!
Mike
Department of Natural Resources and Environmental Sciences
University of Illinois

        [[alternative HTML version deleted]]

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to