Description Usage Arguments Value Note Author(s) References Examples
Change the column classes of variables in a data.frame
that has
already been read into your workspace.
1 | toColClasses(inDF, colClasses)
|
inDF |
The source |
colClasses |
A character vector of the desired column classes. This
should be the same length as the number of columns in the |
A data.frame
.
This function has only been tested with a very small set of the
as.*
functions.
Ananda Mahto
http://stackoverflow.com/a/18893672/1270695
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | mydf <- data.frame(
a = c(" 1"," 2", " 3"),
b = c("a","b","c"),
c = c(" 1.0", "NA", " 2.0"),
d = c(" 1", "B", "2"),
e = c(1, 0, 1))
mydf
str(mydf)
x <- toColClasses(mydf, c("as.integer", "", "as.numeric",
"as.factor", "as.logical"))
x
str(x)
y <- toColClasses(mydf, c("as.integer", "", "as.numeric",
"as.character", "as.logical"))
y
str(y)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.