mardi 11 juin 2019

The condition has length > 1 and only the first element will be used (if - elseif - else) [duplicate]

I have a data frame with a column named "Family", which as the name suggests contains different families (some duplicates). The families were detected with two pipelines. I already did an edgeR analysis and determined significantly abundant families.

I want to add a new column to this data frame that contains either ASV, OTU, Both or None, based on whether the family is significant in ASV pipeline, OTU pipeline, both pipelines, or none.

I'm using following if loop:

if(data1$Family == "f__Trimorphomycetaceae"){
    data1$Significance <- "OTU"
    } else if(data1$Family == "f__Sordariaceae"){
      data1$Significance <- "OTU"
    } else if(data1$Family == "f__Hypocreales_fam_Incertae_sedis"){
      data1$Significance <- "OTU"
    } else if(data1$Family == "f__Tremellaceae"){
      data1$Significance <- "ASV"
    } else if(data1$Family == "f__Spizellomycetaceae"){
      data1$Significance <- "ASV"
    } else if(data1$Family == "f__Pseudeurotiaceae"){
      data1$Significance <- "ASV"
    } else if(data1$Family == "f__Leptosphaeriaceae"){
      data1$Significance <- "ASV"
    } else if(data1$Family == "f__Protrudomycetaceae"){
      data1$Significance <- "Both"
    } else if(data1$Family == "f__Helotiaceae"){
      data1$Significance <- "Both"
    } else {
      data1$Significance <- "None"
    }

I get a warning: "the condition has length > 1 and only the first element will be used".

The result is that the column contains only "None".

Aucun commentaire:

Enregistrer un commentaire