lapply is probably a better choice than apply here, as they apply the first collages of your data.frame file to the array, which means that all columns must be of the same type. Depending on your context, this may have unintended consequences.
Sample:
df[cols] <- lapply(df[cols], FUN)
The vector "cols" may be variable names or indexes. I prefer to use names whenever possible (it is resistant to reordering columns). Therefore, in your case, it could be:
wifi[4:9] <- lapply(wifi[4:9], A)
An example of using column names:
wifi <- data.frame(A=1:4, B=runif(4), C=5:9) wifi[c("B", "C")] <- lapply(wifi[c("B", "C")], function(x) -1 * x)
leif Aug 29 '13 at 6:36 on 2013-08-29 06:36
source share