I'm trying to learn how to use apply (or any other members of the family of apply) to loop over variables in a data.frame
For example: say I have the following data.frame
df_long <- data.frame(id=c(1,1,1,1,2,2,2,2,3,3,3,3),
country=c('a','a','a','a','b','b','b','b','c','c','c','c'),
year=c(1,2,3,4,1,2,3,4,1,2,3,4),
amt = c(3,4,23,5,76,5,2,3,5,4,6,2))
and I want to loop through all the variables such that if the variable is numeric, then I had one to it, else I do nothing. I want the return variable to be a data.frame. This is what I have so far but it doesn't work
apply(df_long, 2, function(x) x = ifelse(is.numeric(x), x+1, x))
Any insights on this question or in general how to loop through variables in a data.frame using apply and/or other methods would be greatly appreciated.