sample_n() function in R Language is used to take random sample specimens from a data frame.
Syntax: sample_n(x, n)
x: Data Frame
n: size/number of items to select
name age ht school 1 Chaman 9 NA no 2 Abhi 7 46 yes 3 Bhavesh 5 NA yes
 Chaman Bhavesh Dimri Levels: Abhi Bhavesh Chaman Dimri
Here, in the above code, column name is specified. Hence, the size is applied within the factor.
- Convert an Object to Data Frame in R Programming - as.data.frame() Function
- Check if the Object is a Data Frame in R Programming - is.data.frame() Function
- Convert a Data Frame into a Numeric Matrix in R Programming - data.matrix() Function
- Modify Data of a Data Frame with an Expression in R Programming - with() Function
- Accessing variables of a data frame in R Programming - attach() and detach() function
- Get Transpose of a Matrix or Data Frame in R Programming - t() Function
- Create a Data Frame of all the Combinations of Vectors passed as Argument in R Programming - expand.grid() Function
- Create Subsets of a Data frame in R Programming - subset() Function
- Convert a Data Frame into a Molten Form in R Programming - melt() Function
- Rename Columns of a Data Frame in R Programming - rename() Function
- Choose Specific Columns of a Data Frame in R Programming - select() Function
- Add new Variables to a Data Frame using Existing Variables in R Programming - mutate() Function
- Condense Column Values of a Data Frame in R Programming - summarise() Function
- Create Matrix and Data Frame from Lists in R Programming
- Creating a Data Frame from Vectors in R Programming
- Generate Data sets of same Random Values in R Programming - set.seed() Function
- Modify values of a Data Frame in R Language - transform() Function
- Binding rows and columns of a Data Frame in R - bind_rows() and bind_cols() Function
- Create a Random Sequence of Numbers within t-Distribution in R Programming - rt() Function
- Create Random Deviates of Uniform Distribution in R Programming - runif() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.