R Apply() function on specific dataframe columns
I want to use the apply function on a dataframe, but only apply the function to the last 5 columns. B<- by(wifi,(wifi$Room),FUN=function(y){apply(y, 2, A)}) This applies A to all the columns of y B<- by(wifi,(wifi$Room),FUN=function(y){apply(y[4:9], 2, A)}) This applies A only to columns 4-9 of y, but the total return of B strips off the first 3 columns... I still want those, I just don't want A applied to them. wifi[,1:3]+B also does not do what I expected/wanted. Using an example data.frame and example function (just +1 to all values) A <- function(x) x + 1 wifi <- data.frame(replicate(9,1:4