head() function in R Language is used to get the first parts of a vector, matrix, table, data frame or function.
Syntax: head(x, n)
Parameters:
x: specified data types
n: number of row need to be printed
Example 1:
# R program to illustrate # head function # Calling the head() function to # get the iris demo dataset head(iris) |
chevron_right
filter_none
Output:
Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1 5.1 3.5 1.4 0.2 setosa 2 4.9 3.0 1.4 0.2 setosa 3 4.7 3.2 1.3 0.2 setosa 4 4.6 3.1 1.5 0.2 setosa 5 5.0 3.6 1.4 0.2 setosa 6 5.4 3.9 1.7 0.4 setosa
Example 2:
# R program to illustrate # head function # Calling the head() function to # get the iris demo dataset in # 4 rows head(iris, 4) |
chevron_right
filter_none
Output:
Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1 5.1 3.5 1.4 0.2 setosa 2 4.9 3.0 1.4 0.2 setosa 3 4.7 3.2 1.3 0.2 setosa 4 4.6 3.1 1.5 0.2 setosa
Recommended Posts:
- Get the Last parts of a Data Set in R Programming - tail() Function
- Describe Parts of a Chart in Graphical Form in R Programming - legend() Function
- Generate a set of Sample data from a Data set in R Programming - sample() Function
- Get Transpose of a Matrix or Data Frame in R Programming - t() Function
- 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
- Get or Set Levels of a Factor in R Programming - levels() Function
- Get or Set Dimensions of a Matrix in R Programming - dim() Function
- Get or Set names of Elements of an Object in R Programming - names() Function
- Get or Set the Type of an Object in R Programming - mode() Function
- Get or Set the Structure of a Vector in R Programming - structure() Function
- Get the List of Arguments of a Function in R Programming - args() Function
- Data Wrangling in R Programming - Data Transformation
- Reordering of a Data Set in R Programming - arrange() Function
- Create Quantiles of a Data Set in R Programming - quantile() Function
- Fitting Linear Models to the Data Set in R Programming - glm() Function
- Generate Data sets of same Random Values in R Programming - set.seed() Function
- Get Exclusive Elements between Two Objects in R Programming - setdiff() 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 contribute@geeksforgeeks.org. 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.

