Last active
December 29, 2015 11:19
-
-
Save aammd/7663065 to your computer and use it in GitHub Desktop.
a demostration of using catcolwise -- a function that creates a function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## make a fake data frame | |
test <- data.frame(foo=gl(n=3,k=2,labels=c("low","med","high")),bar=rep(letters[1:2],3),zoop=runif(6)) | |
## these are all factors | |
str(test) | |
## I want them to be characters, not factors, but I am too lazy to run as.character on every categorical factor | |
library(plyr) | |
test_char <- catcolwise(as.character)(test) | |
# success! | |
str(test_char) | |
## OR | |
test2 <- data.frame(apply(test, 2, as.character)) | |
str(test2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment