This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Error input data must be numeric in R, how to solve it?

Error input data must be numeric, how to solve it?

I am trying to perform Alpha diversity for microbiome analysis in R, I got an error when ASV file is the input data although it has numeric values:

Error in diversity(ASV, index = "shannon") : input data must be numeric

error_numeric asv_file r

What is the package you're trying to use here? What does your data look like? It is an Excel file? Is it a CSV file? Or has this "ASV" data been loaded into the environment already?

The data is text file (I opened it as csv to show you) and it looks like that enter image description here

1 answer

I am guessing you are using microbiome::diversity function in the Bioconductor microbiome package. The help page for the function says:

Usage

diversity(x, index = "all", zeroes = TRUE)

Arguments

  • x A species abundance vector, or matrix (taxa/features x samples) with the absolute count data (no relative abundances), or phyloseq-class object
  • index Diversity index. See details for options.
  • zeroes Include zero counts in the diversity estimation.

So it is clear that you need to give the function a numeric vector or matrix, not a data.frame or csv file.

Thanks for your answer, so x is the taxa file?

Please read the help again. x is a vector or a matrix, not a file. You have to create the matrix from the file, for example by:

x <- read.csv("taxa.csv", row.names=1)

Thanks a lot

Log in to answer this question.