tags:

views:

66

answers:

1

I got the below piece of code and it keeps on printing the frequency tables. How do I stop it from doing this.

pl = read.csv("c:/pl.csv")
freqs =  function(name){ assign(name, table(pl[,name],pl$bad_outcome), envir = .GlobalEnv);} 
lapply(names(pl), freqs);
+2  A: 

You have three options:

1) Assign the output, since what you're seeing as "printing" is actually just a return.

x <- lapply(names(pl), freqs)

2) Use the l_ply function in plyr.

library(plyr)
l_ply(names(pl), freqs)

3) Don't do the assign inside the lapply, but do it afterwards with attach:

x <- lapply(names(pl), function(name) table(pl[,name],pl$bad_outcome))
attach(x)
Shane
With respect to 3), be aware that `attach(object)` should be used with care. Using it repeatedly can cause problems, without appropriate use of `detach(object)`
nullglob