Deloitte Interview Questions | What is the difference between subset() function and sample() function in R?
Question
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
It will take less than 1 minute to register for lifetime. Bonus Tip - We don't send OTP to your email id Make Sure to use your own email id for free books and giveaways
Answers ( 3 )
Sample function in R, generates a sample of the specified size from the data set or elements, either with or without replacement.
The subset function is available in base R and can be used to return subsets of a vector, martix, or data frame which meet a particular condition.
Sample takes a sample of the specified size from the elements of the data using
either with or without replacement.
Subset returns subset of vectors, matrices or data frames which meet conditions
you provide..
sample( ) function to take a random sample of size n from a dataset.
subset( ) function is the way to select variables and observations.