As mentioned, you simply want the standard R apply
function applied to columns (MARGIN=2
):
wifi[,4:9] <- apply(wifi[,4:9], MARGIN=2, FUN=A)
Or, for short:
wifi[,4:9] <- apply(wifi[,4:9], 2, A)
This updates columns 4:9 in-place using the A()
function. Now, let's assume that na.rm
is an argument to A()
, which it probably should be. We can pass na.rm=T
to remove NA values from the computation like so:
wifi[,4:9] <- apply(wifi[,4:9], MARGIN=2, FUN=A, na.rm=T)
The same is true for any other arguments you want to pass to your custom function.