Q:

How to apply a function to specific classes of objects in R

I have a large dataframe with variables of different class. I want to apply a function only to variables of class factor. How can I do that?

A:

Try something like this:
lapply(data, function(x) if(is.factor(x)) foo(x) else x)

