0

I am analyzing bacterial 16S data extracted from vegetarian food samples and would like to combine two data frames of different row and column lengths into one data frame. The two data frames are:

taxa = 5081 entries and 6 columns

genus.species = 1661 entries and 2 columns
  • Example of what "taxa" looks like:
Sequence Kingdom   Phylum        Class            Order       Family Genus 

x        Bacteria  CyanoBacteria Oxyphotobacteria Chloroplast N/A    N/A
  • Example of what "genus.species" looks like:
Sequence Genus Species

x        N/A   N/A

I have tried appending empty rows to the end of the genus.species file so that it has the same number of rows than that of the taxa file but have been unsuccessful. Are there other ways to circumvent this issue?

genus.species <- assignSpecies(Food_Bac16S_Meg_nochim_sumtable,
                 "C:/Users/DELL/Desktop/University of Western Cape/Masters/Thesis/Analysis/Bacterial_16S_Data_Trimmed/silva_species_assignment_v132.fa", 
                 allowMultiple=FALSE)

taxa <- assignTaxonomy(Food_Bac16S_Meg_sumtable, 
        "C:/Users/DELL/Desktop/University of Western Cape/Masters/Thesis/Analysis/Bacterial_16S_Data_Trimmed/silva_nr_v132_train_set.fa", 
        multithread=TRUE)

taxa_sp <- data.frame(taxa[,1], taxa[,2], taxa[,3], taxa[,4], taxa[,5], taxa[,6], genus.species[,2])

I expected that these two data frames will create one data frame that will go through all the sequences within the taxa file and will append the genus.species file to the end of the column of the correct sequences, however, I receive this error:

Error in data.frame(taxa[, 1], taxa[, 2], taxa[, 3], taxa[, 4], taxa[,  : 
  arguments imply differing number of rows: 5081, 1661

So ultimately, how do I join two data frames into one if they have different row and column lengths? Any help will be much appreciated.

Z.Lin
  • 28,055
  • 6
  • 54
  • 94
MegsDJ
  • 1
  • 1
  • Are you perhaps after a `merge`? In which case this would be a duplicate of [How to join (merge) data frames (inner, outer, left, right)](https://stackoverflow.com/questions/1299871/how-to-join-merge-data-frames-inner-outer-left-right). – Maurits Evers Oct 14 '19 at 02:40
  • I've closed this as a dupe for now. If your issue is different, please provide a minimal & reproducible example including sample data, and leave a comment and/or flag for re-open. – Maurits Evers Oct 14 '19 at 02:43

0 Answers0