change lapply to sapply
locally smooth curve
added class 5 r code