Using apply, sapply, lapply in R