R Func Head Tail
# R head() and tail() Functions - View Data Head and Tail
[ R Language Examples](https://example.com/r/r-examples.html)
R head() function is used to view the first few rows of data, and tail() views the last few rows.
These two functions are the first step in data exploration, used to quickly understand the data structure.
The syntax for head() and tail() functions is as follows:
head(x, n = 6) tail(x, n = 6)
**Parameter Description:**
* **x** Input object (vector, data frame, matrix, etc.).
* **n** Number of rows to display, default is 6.
## Example
# Generate large data frame
set.seed(123)
df<-data.frame(
ID =1:100,
Score =round(rnorm(100, mean=70, sd=15), 1)
)
print("Before 10 line:")
print(head(df, 10))
print("Post 5 line:")
print(tail(df, 5))
Executing the above code outputs:
"Before 10 line:" ID Score1 1 61.62 2 66.53 3 93.44 4 71.15 5 71.96 6 95.77 7 76.98 8 51.09 9 59.710 10 63.3 "Post 5 line:" ID Score96 96 70.997 97 53.398 98 62.199 99 64.1100 100 78.9
[ R Language Examples](https://example.com/r/r-examples.html)
YouTip