What is the difference between the subset() and sample() functions n R?

The subset() function in R is used for extracting rows and columns from a data frame or a matrix, or elements from a vector, based on certain conditions, e.g.: subset(my_vector, my_vector > 10).

Instead, the sample() function in R can be applied only to vectors. It extracts a random sample of the predefined size from the elements of a vector, with or without replacement. For example, sample(my_vector, size=5, replace=TRUE)


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *