0

I am trying to use a taxonomy file to run a species curve using the package vegan and the function specaccum, but I keep getting the error:

Error in colSums(x) : 'x' must be numeric

This file is a huge table, with species taxonomy in the first column, and sites in the next ones. Like this:

sum.taxonomy | K0024.A2.S1.L001.x | K0024.B2.S9.L001.x
Acantharea;Arthracanthida;Acanthometridae;Acanthometra; | 0 | 57
Acantharea;Chaunacanthida;NA;; | 3 | 0

Each value is a number corresponding to the number of reads. I've tried uploading this file in multiple ways, I've looked for missing values, I've tried forcing the table as.numeric and still no success.

This is the command I thought would work:

    table <- read.table("All_reads_all_markers_all_samples_after_decontamination.txt", 
             header = TRUE, sep = "\t",  quote = "", comment.char = "", 
             row.names = 1, stringsAsFactors = F)
    specaccum(table, method = "rarefaction")

I don't know what I'm missing here. Any help would be greatly appreciated!

I'm using RStudio v1.1.383, R v3.5.0, and vegan v2.5.1 in a Windows 10.

Rachel
  • 73
  • 7
  • How did you go from `table` to `test`? Please share your data so others can help (post the outputs from `dput(table)` & `dput(test)) – Tung May 16 '18 at 04:29
  • 2
    You really should not argue with a computer: Computer is much more pedantic than you, and if it finds non-numeric data, then you have non-numeric data. Your task is only to find that conflicting item yourself. – Jari Oksanen May 16 '18 at 08:00
  • Check out the structure of table and test with `str(table)` or as @Tung mentioned, with `dput()`. If you see that a column is not numeric, although it should be, you have to convert it to numeric -> `table$variable <- as.numeric(table$variable)` – SeGa May 16 '18 at 09:05
  • 1
    NB, `as.numeric()` only changes factors to numeric, but you read your non-numeric data as characters (`stringAsFactors = FALSE)`. These cannot be turned into numeric. OTOH, you should not turn factors to numeric either, because this makes no sense in `specaccum`. You got to find the columns that really should be numeric and take care that they are numeric, and correct numbers, too. – Jari Oksanen May 16 '18 at 11:07
  • 1
    sorry, @Tung, that was a typo! and you were right! there was a stupid `'` inside a single cell from the more the 20000 ones, that with the help of a friend we were able to track down. we did the following: `ttt=apply(table,MARGIN = 1:2,FUN = as.numeric)`, then `which(is.na(ttt[,1]))` we changed the column numbers decreasingly from 150 to 1 (of course it was on the last one), and then searched the row in that column. not fun! :( – Rachel Jun 13 '18 at 21:03

0 Answers0