Error input data must be numeric in R, how to solve it?
1
0
Entering edit mode
2.0 years ago
Amr ▴ 180

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 • 3.0k views
ADD COMMENT
1
Entering edit mode

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?

ADD REPLY
0
Entering edit mode

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

ADD REPLY
2
Entering edit mode
2.0 years ago
Gordon Smyth ★ 7.7k

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.

ADD COMMENT
0
Entering edit mode

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

ADD REPLY
1
Entering edit mode

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)
ADD REPLY
0
Entering edit mode

Thanks a lot

ADD REPLY

Login before adding your answer.

Traffic: 2090 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6