Subset() is used to select the variables and observations and sample() function is used to  generate  a random sample of the size n from a dataset.