I am trying to calculate the row median for a data frame df
with rowMedians
from matrixStats
package.
Abundance Sample1 Sample2 Sample3 Sample4 Sample5 Sample6 Sample7
Species1 2 4 0 0 0 6 0
Species2 3 5 6 4 0 0 0
Species3 3 7 2 5 8 0 0
Species4 0 0 3 8 0 0 8
Species5 7 5 6 0 0 4 4
Species6 4 2 3 0 0 2 1
I want to calculate the median of every row and append them in a new column. I got an error
Argument 'x' must be a vector or matrix
so I tried to convert my df
to a matrix. The str
function shows that every value for the species is numeric, so I tried:
library(matrixStats)
matrix(df, rownames.force = NA)
rowMedians(df)
but I am still getting the same error. Any help is appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…