title: re-arrange mixed input dataframe
body: <p>I have an input dataframe that is not consistent. Here it is.</p>
  
  <pre><code>df &lt;- structure(list(Gene = c("k141_1305_1", "k141_1406_2", "k141_1406_3", 
  "k141_6669_1", "k141_9215_1", "k141_13242_1", "k141_13333_5", 
  "k141_17708_1", "k141_19670_1", "k141_19670_6"), Phylum = c("p__Actinobacteria", 
  "p__Firmicutes", "p__Firmicutes", "p__Cyanobacteria", "p__Actinobacteria", 
  "p__Actinobacteria", "p__Firmicutes", "p__Firmicutes", "p__Actinobacteria", 
  "p__Proteobacteria"), Class = c("c__Actinobacteria", "c__Clostridia", 
  "c__Clostridia", "o__Nostocales", "c__Actinobacteria", "c__Actinobacteria", 
  "c__Clostridia", "c__Bacilli", "c__Actinobacteria", "c__Gammaproteobacteria"
  ), Order = c("o__Pseudonocardiales", "o__Clostridiales", "o__Clostridiales", 
  "f__Hapalosiphonaceae", "o__Pseudonocardiales", "o__Pseudonocardiales", 
  "o__Clostridiales", "o__Bacillales", "o__Pseudonocardiales", 
  "o__Pseudomonadales"), Family = c("f__Pseudonocardiaceae", "f__Lachnospiraceae", 
  "f__Lachnospiraceae", "g__Fischerella", "f__Pseudonocardiaceae", 
  "f__Pseudonocardiaceae", "f__Clostridiales Family XIII. Incertae Sedis", 
  "g__Exiguobacterium", "f__Pseudonocardiaceae", "f__Pseudomonadaceae"
  ), Genus = c("g__Pseudonocardia", "s__Lachnospiraceae bacterium 10-1", 
  "s__Lachnospiraceae bacterium 10-1", "s__Fischerella muscicola", 
  "g__Pseudonocardia", "g__Pseudonocardia", "s__[Eubacterium] infirmum", 
  "s__Exiguobacterium enclense", "g__Pseudonocardia", "g__Pseudomonas"
  ), Species = c("s__Pseudonocardia sp. Ae331_Ps2", "unknown", 
  "unknown", "unknown", "s__Pseudonocardia sp. Ae331_Ps2", "s__Pseudonocardia sp. Ae331_Ps2", 
  "unknown", "unknown", "s__Pseudonocardia ammonioxydans", "s__Pseudomonas aeruginosa group"
  )), .Names = c("Gene", "Phylum", "Class", "Order", "Family", 
  "Genus", "Species"), row.names = c(3212L, 3853L, 3854L, 17967L, 
  24006L, 34126L, 34325L, 43722L, 49328L, 49332L), class = "data.frame")
  </code></pre>
  
  <p>The dataframe looks like this</p>
  
  <pre><code> Gene            Phylum             Class                Order                Family
  3212   k141_1305_1 p__Actinobacteria c__Actinobacteria o__Pseudonocardiales f__Pseudonocardiaceae
  3853   k141_1406_2     p__Firmicutes     c__Clostridia     o__Clostridiales    f__Lachnospiraceae
  3854   k141_1406_3     p__Firmicutes     c__Clostridia     o__Clostridiales    f__Lachnospiraceae
  17967  k141_6669_1  p__Cyanobacteria     o__Nostocales f__Hapalosiphonaceae        g__Fischerella
  24006  k141_9215_1 p__Actinobacteria c__Actinobacteria o__Pseudonocardiales f__Pseudonocardiaceae
  34126 k141_13242_1 p__Actinobacteria c__Actinobacteria o__Pseudonocardiales f__Pseudonocardiaceae
                                    Genus                         Species
  3212                  g__Pseudonocardia s__Pseudonocardia sp. Ae331_Ps2
  3853  s__Lachnospiraceae bacterium 10-1                         unknown
  3854  s__Lachnospiraceae bacterium 10-1                         unknown
  17967          s__Fischerella muscicola                         unknown
  24006                 g__Pseudonocardia s__Pseudonocardia sp. Ae331_Ps2
  34126                 g__Pseudonocardia s__Pseudonocardia sp. Ae331_Ps2
  </code></pre>
  
  <p>As you can see the dataframe is not structured as it should be. The dataframe was generated this way so i don´t have control over it.</p>
  
  <p>The problem is that microorganisms should be annotated using different ranks (from Pylum to species, one per column). As you can see in some cases there are missing ranks , for example Gene 17967 (4th row) does not have a class rank (no "c__" annotation). What happens is that in the column class this particular taxa has the order ("o__Nostocales") instead of an empty "c__" annotation. 
  Same happens for others, for example 2nd row does not have genus "g__" annotation so the species is put in the genus column.</p>
  
  <p>The first and two last rows are an example of how it should be. </p>
  
  <p>Is there a chance to correct those rows in a quick way so that each colum has it corresponding taxonomic rank. ???</p>
  
  <p>For example if i take the second row the correct output should be:</p>
  
  <pre><code>Gene            Phylum             Class                Order                Family 
       3853   k141_1406_2     p__Firmicutes     c__Clostridia     o__Clostridiales    f__Lachnospiraceae
            Genus    Species
      3853  g__ s__Lachnospiraceae bacterium 10-1 
  </code></pre>
  
  <p>Alternatevely it could be an unknown g__unknown tag.</p>
  
  <pre><code>3853   k141_1406_2     p__Firmicutes     c__Clostridia     o__Clostridiales    f__Lachnospiraceae
   3853  g__unknown s__Lachnospiraceae bacterium 10-1 
  </code></pre>