I'm trying to subset a dataframe according to the value of a column which can change name over different versions of the dataframe. The value I want to test for is "----" in a column named either "SIC" or "NAICS".
Version 1:
df
  MSA  SIC EMPFLAG   EMP
1  40 ----         43372
2  40 07--           192
3  40 0700           192
Version 2:
df
  MSA NAICS EMPFLAG   EMP
1  40  ----         78945
2  40  07--           221
3  40  0700           221
The expect result is:
Version 1:
df
  MSA   EMP
1  40 43372
Version 2:
df
  MSA   EMP
1  40 78945
The following code doesn't work:
df <- ifelse("SIC" %in% colnames(df), 
             df[df$SIC=="----", c("MSA", "EMP")], 
             df[df$NAICS=="----", c("MSA", "EMP")])
 
     
    