Description Usage Arguments Details Value Note Author(s) References See Also Examples
View source: R/BioGeoBEARS_generics_v1.R
This function converts each column to class
numeric
where possible, and class
character
otherwise.
1 2 | dfnums_to_numeric(dtf, max_NAs = 0.5, printout = FALSE,
roundval = NULL)
|
dtf |
Input |
max_NAs |
Non-numeric cells will get converted to
NA, up to the fraction of cells specified by
|
printout |
Print the results to screen, if desired. |
roundval |
If not NULL, |
R does lots of weird and unpredictable things when you
build up tables/matrices/data.frames by e.g.
cbind
and rbind
on vectors of results. The major problems are (1)
columns get made into class list
; (2)
numeric
columns are converted to
class factor
; (3)
numeric
columns are converted to
class character
; (4) you have a
matrix
when you think you have a
data.frame
.
All of this could be taken care of by detailed
understanding and tracking of when R recasts values in
vectors, matrices, and data frames...but this is a huge
pain, it is easier to just have a function that jams
everything back to a data.frame
with
no lists, no factors, and with columns being numeric
where possible. See unlist_df4
for more,
and cls.df
to see the class of each column.
WARNING: IF A COLUMN IS A MIX OF NUMBERS AND
NON-NUMBERS, THE NON-NUMBERS WILL BE CONVERTED TO NA IF
THE COLUMN IS MAJORITY NUMBERS (on default; see
max_NAs
).
dtf
The output data.frame
.
Go BEARS!
Nicholas J. Matzke matzke@berkeley.edu
http://phylo.wikidot.com/matzke-2013-international-biogeography-society-poster
Matzke_2012_IBS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | x = matrix(c(1,2,3,4,5,6), nrow=3, ncol=2)
cls.df(x)
dfnums_to_numeric(adf(x))
unlist_df4(x)
x = matrix(c(1,2,3,4,5,"A"), nrow=3, ncol=2)
cls.df(x)
dfnums_to_numeric(adf(x))
unlist_df4(x)
x = adf(matrix(c(1,2,3,4,5,"A"), nrow=3, ncol=2))
names(x) = c("A","B")
cls.df(x)
dfnums_to_numeric(adf(x))
unlist_df4(x)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.