Your code looks fine. I suspect you have a package conflict that has masked the select() function from dplyr. Try replacing select() with dplyr::select() and see if that works?
By the way, if this is a homework assignment, please read our homework policy: