Skip to content

Instantly share code, notes, and snippets.

@aammd
Last active December 29, 2015 11:19
Show Gist options
  • Save aammd/7663065 to your computer and use it in GitHub Desktop.
Save aammd/7663065 to your computer and use it in GitHub Desktop.
a demostration of using catcolwise -- a function that creates a function.
## 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