Using lapply instead or for loops