apply functions in R

It takes a lot of time to run for loop, apply function is different and based on C language, which saves a lot of time.

apply family

apply() can be applied to matrix, dataframe, array
apply(X,MARGIN,FUN), X: dataframe,matrix,array; MARGIN: applied to rows when =1, applied to columns when =2; FUN: function that apply to the data

apply a given function to every element of a list and obtain a list as result, it can be applied to dataframes, lists or vectors, the output
return to a list
lapply cannot be applied to vector or matrix

similar to lapply, but return to vector, not list
X can be array, matrix, dataframe
simplify: whether to array
USE.NAMES: if X is a string, then TRUE set string as the data name
if simplify=FALSE and USE.NAMES=FALSE, then sapply is equal to lapply
if simplify=array then can create matrixes
if USE.NAMES=TRUE, then can create data name

it is similar to sapply