cls.df: Get the class for each column in a list

Description Usage Arguments Details Value Note Author(s) References See Also Examples

View source: R/BioGeoBEARS_generics_v1.R

Description

This function returns the class of each column in a data.frame.

Usage

1
  cls.df(dtf, printout = FALSE)

Arguments

dtf

Input data.frame.

printout

Print the results to screen, if desired.

Details

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 dfnums_to_numeric and unlist_df4 for these options.

Value

dtf_classes A data.frame showing the column, column name, and column class.

Note

Go BEARS!

Author(s)

Nicholas J. Matzke matzke@berkeley.edu

References

http://phylo.wikidot.com/matzke-2013-international-biogeography-society-poster

Matzke_2012_IBS

See Also

dfnums_to_numeric, unlist_df4

Examples

 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)

BioGeoBEARS documentation built on May 29, 2017, 8:36 p.m.