Earlier quoted context omitted.
I use a simply device to keep these straight: - (l)apply: List apply always returns a list - (s)apply: simplify apply tries to return simplified result - (v)apply: verify apply checks the return type conforms to user supplied example - (m)apply: multiple apply applies FUN to multiple vectors - (r)apply: recursive apply is essentially a flatmap - apply : no device here, only use on matrices, never data.frames
After reading your explanation I still, as has been the case for years, don't understand what sapply or rapply does, and vapply sounds weird. That isn't going to change, because I'm just not going to use them or 'invest' the time in finding out what some statistician-of-yore's interpretation of a map is. Instead I'll stick to tidyverse map - returns a list. Or tidyverse map_[int/chr/dbl/etc, etc] if I want a vector o…
There is nothing complicated about what sapply does... It simply means loop over the elements of the first argument (which must be a list; btw a dataframe, df, is internally the same as a list) and apply some function. lapply does this and returns a list, sapply does this and can optionally "simplify" the results into a vector, etc.
So:
lapply(df, class) = loop over the elements of df and tell me the class, return this in the form of a list
sapply(df, class) = loop over the elements of df and tell me the class, return this as a character vector
This is basically lapply:
res = NULL
for(i in 1:length(df)){
res = append(res, class(df[i]))
}
return(res)