I have an abundance dataframe improved as a csv with column and row headers. When imported, and running str(data) it shows each row as int. I can't use vegan's package specaccum unless the data is numeric. After converting my dataframe into numeric it is still producing the following error:
Error in colSums(x) : 'x' must be numeric
My sample and code:
Structure of my dataframe before any conversion:
> str(data)
'data.frame': 180 obs. of 727 variables:
$ Sample : Factor w/ 180 levels "Sample1","Sample2",..: 1 2 3 4 5 6 7 8 9 10 ...
$ Abrostola : int 0 0 0 0 0 0 0 0 0 0 ...
$ Abrus : int 0 0 1 0 0 0 0 0 0 0 ...
$ Acanthamoeba : int 0 0 0 0 0 0 0 0 0 0 ...
$ Acanthopagrus : int 0 0 0 0 0 0 1 0 0 0 ...
$ Acetilactobacillus : int 0 1 0 0 0 0 0 0 0 0 ...
$ Acetobacter : int 0 0 0 0 0 0 0 0 0 0 ...
Then:
data2 <- data[-1] ## to get rid of factor column
data2 <- lapply(data2, as.numeric)
> str(data2)
List of 726
$ Abrostola : num [1:180] 0 0 0 0 0 0 0 0 0 0 ...
$ Abrus : num [1:180] 0 0 1 0 0 0 0 0 0 0 ...
$ Acanthamoeba : num [1:180] 0 0 0 0 0 0 0 0 0 0 ...
$ Acanthopagrus : num [1:180] 0 0 0 0 0 0 1 0 0 0 ...
$ Acetilactobacillus : num [1:180] 0 1 0 0 0 0 0 0 0 0 ...
$ Acetobacter : num [1:180] 0 0 0 0 0 0 0 0 0 0 ...
$ Achromobacter : num [1:180] 0 0 0 0 0 0 0 0 0 0 ...
$ Acinetobacter : num [1:180] 0 0 0 0 0 0 0 0 0 0 ...
Next I tried running the very basic vegan command:
mycurve <- specaccum(comm = data2, method = "random", permutations = "1000")
But it gives the same error. I don't get it - my df is clearly converted to numeric so what is the issue??
EDIT
Prior to fixing my dataframe into numeric, I was using:
mycurve <- specaccum(comm = data[-1], method = "random", permutations = "1000") ## without prior removal of factor column
But it was giving the following error:
Error in nperm + EPS : non-numeric argument to binary operator
$ Acetobacter : num [1:180] 0 0 0 0 0 0 0 0 0 0 ...
I am not sure why it is targeting this particular column, it looks exactly the same as everything else. No columns are empty (i.e. no column sums equal 0 as I thought that would be causing an issue). I checked for weird symbols/whitespace - the columns do not have anything out of the ordinary. There are no empty cells either with "NA".
Output of dput(head(data)) but due to body limit in this post I had to truncate the output.
structure(list(Sample = structure(1:6, .Label = c("Sample1", "Sample2",
"Sample3", "Sample4", "Sample5", "Sample6", "Sample180"), class = "factor"), Abrostola = c(0L,
0L, 0L, 0L, 0L, 0L), Abrus = c(0L, 0L, 1L, 0L, 0L, 0L), Acanthamoeba = c(0L,
0L, 0L, 0L, 0L, 0L), Acanthopagrus = c(0L, 0L, 0L, 0L, 0L, 0L
), Acetilactobacillus = c(0L, 1L, 0L, 0L, 0L, 0L), Acetobacter = c(0L,
0L, 0L, 0L, 0L, 0L), Achromobacter = c(0L, 0L, 0L, 0L, 0L, 0L
), Acinetobacter = c(0L, 0L, 0L, 0L, 0L, 0L), Acipenser = c(0L,
0L, 0L, 0L, 0L, 0L), Acomys = c(0L, 0L, 0L, 0L, 0L, 0L), Acremonium = c(0L,
0L, 0L, 0L, 0L, 0L), Acromyrmex = c(0L, 0L, 0L, 0L, 0L, 0L),
Acropora = c(0L, 0L, 0L, 0L, 0L, 0L), Actinidia = c(0L, 0L,
0L, 0L, 0L, 0L), Actinobacillus = c(0L, 0L, 0L, 0L, 0L, 0L
), Acyrthosiphon = c(0L, 0L, 0L, 0L, 0L, 0L), Acytostelium = c(0L,
1L, 0L, 0L, 0L, 0L), Aedes = c(0L, 0L, 0L, 0L, 0L, 0L), Aegilops = c(0L,
0L, 0L, 0L, 0L, 0L), Aeromonas = c(0L, 0L, 0L, 0L, 5L, 0L
), Ageratum = c(0L, 0L, 0L, 0L, 0L, 0L), Aggregatibacter = c(0L,
0L, 0L, 0L, 0L, 0L), Albugo = c(0L, 0L, 0L, 0L, 0L, 0L),
Alcaligenes = c(0L, 0L, 0L, 0L, 0L, 0L), Alcanivorax = c(0L,
0L, 0L, 0L, 0L, 0L), Allygidius = c(0L, 0L, 0L, 0L, 0L, 0L
), Amblyraja = c(0L, 0L, 0L, 0L, 0L, 0L), Amoebogregarina = c(0L,
0L, 1L, 1L, 0L, 0L), Amphidinium = c(0L, 0L, 0L, 0L, 0L,
0L), Amphiprion = c(0L, 0L, 0L, 0L, 0L, 0L), Amphipyra = c(0L,
1L, 1L, 1L, 0L, 1L), Amycolatopsis = c(0L, 0L, 0L, 0L, 0L,
0L), Ananas = c(1L, 1L, 1L, 1L, 0L, 0L), Anas = c(0L, 0L,
0L, 0L, 0L, 0L), Andhravirus = c(0L, 0L, 0L, 0L, 0L, 0L),
Andrena = c(0L, 0L, 0L, 0L, 0L, 0L), Anolis = c(0L, 0L, 0L,
0L, 0L, 0L), Anopheles = c(0L, 1L, 0L, 0L, 0L, 0L), Anoplophora = c(0L,
0L, 0L, 0L, 0L, 0L), Anoxybacillus = c(0L, 0L, 0L, 0L, 0L,
0L), Anthocharis = c(0L, 1L, 2L, 1L, 0L, 1L), Aphanomyces = c(0L,
0L, 0L, 1L, 0L, 0L), Aphyllon = c(0L, 0L, 0L, 0L, 0L, 0L),
Apilactobacillus = c(2L, 0L, 0L, 0L, 0L, 0L), Apotomis = c(0L,
0L, 0L, 0L, 0L, 0L), Apteryx = c(0L, 0L, 0L, 0L, 0L, 0L),
Aquila = c(0L, 0L, 0L, 0L, 0L, 0L), Arabidopsis = c(0L, 0L,
0L, 0L, 0L, 0L), Arabis = c(0L, 0L, 0L, 0L, 0L, 0L), Arachis = c(0L,
0L, 0L, 0L, 0L, 0L), Arctia = c(0L, 0L, 0L, 0L, 0L, 0L)), row.names = c(NA, 6L), class = "data.frame")
SOLVED
While the code I was using for mycurve was working with other method options and quoting permutations, simply removing the quotes for permutations along with method random worked. Did not even need to convert the data into numeric.
mycurve <- specaccum(comm = data[-1], method = "random", permutations = 1000) ## REMOVED QUOTES IN PERMUTATIONS and used with INT dataframe
specaccum(comm = data[[-1]], method = "random", permutations = "1000")Error in .subset2(x, i, exact = exact) : attempt to select more than one element in get1index <real>data2is alistobject. Please convert it to adataframe.