Created
November 13, 2012 03:03
-
-
Save kdaily/4063700 to your computer and use it in GitHub Desktop.
Example for using plyr to replace strings in multiple columns
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
## Need plyr | |
require(plyr) | |
## Some fake data | |
foo <- data.frame(a=rep("foo", 3), b=rep("foofoo", 3), c=rep("foobarfoo", 3)) | |
## Replace function, works on vectors | |
fn <- function(x) gsub("foo", "bar", x) | |
## Turn it into a column-wise function; only apply to cols "a" and "b" | |
fncol <- colwise(fn, .cols=c("a", "b")) | |
## Apply the function | |
fncol(foo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment