Closed qdread closed 3 years ago
Actually, I'm not sure what Pat meant here because the matrices in the output of Ostats()
are already named. See line 130 of Ostats.R
:
# Name rows and columns of the outputs.
dimnames(overlaps_norm) <- list(levels(plots), dimnames(traits)[[2]])
dimnames(overlaps_unnorm) <- list(levels(plots), dimnames(traits)[[2]])
@billspat Can you please clarify what you meant?
Really possible I am mistaken, or I missed something or maybe it was from my non-dplyr filtering, but I get null column names. The row names work great.
library(Ostats)
dat <- read.csv('https://ndownloader.figshare.com/files/9167548', stringsAsFactors =FALSE)
dat <- dat[!is.na(dat$logweight) & dat$siteID %in% c('HARV','JORN'),
c('siteID', 'taxonID', 'weight', "logweight") ]
names(dat)
# [1] "siteID" "taxonID" "weight" "logweight"
Ostats_example2 <- Ostats(traits = as.matrix(dat[,'logweight']),
sp = factor(dat$taxonID),
plots = factor(dat$siteID),
density_args=list(bw = 'nrd0', adjust = 2, n=200))
Ostats_example2 <- Ostats(traits = as.matrix(dat[,'logweight']),
sp = factor(dat$taxonID),
plots = factor(dat$siteID),
density_args=list(bw = 'nrd0', adjust = 2, n=200))
mat = Ostats_example2$overlaps_norm
mat
# [,1]
# HARV 0.89454559
# JORN 0.01820969
names(mat)
# NULL
@billspat thanks for the reprex! I determined this was a result of R's "helpful" default behavior of converting a matrix to a vector if only a single column is selected with the indexing operator [
, which strips the names. I pushed a commit 1fe07d6 which adds drop = FALSE
to all the indexing of single columns done in the vignette, which should result in the names being preserved. For example as.matrix(dat[,'logweight', drop = FALSE]
Comment from Pat in email: