Useful R function for general data analysis and plotting