R function to create a regular grid