Can you provide a reproducible example?
Otherwise, have a look at these articles. You should be able to do what you need.