R语言 获取数据集的第一部分 – head()函数

R语言 获取数据集的第一部分 – head()函数

R语言中的 head() 函数用于获取一个向量、矩阵、表格、数据框或函数的第一部分。

语法: head(x, n)

参数:

x: 指定的数据类型

n: 需要打印的行数

例1 :

# R program to illustrate
# head function
  
# Calling the head() function to 
# get the iris demo dataset
head(iris)
R

输出

  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
R

例2 :

# R program to illustrate
# head function
  
# Calling the head() function to 
# get the iris demo dataset in
# 4 rows
head(iris, 4)
R

输出

  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
R

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

登录

注册