📜  获取R中DataFrame的统计汇总和性质

📅  最后修改于: 2022-05-13 01:55:29.856000             🧑  作者: Mango

获取R中DataFrame的统计汇总和性质

在本文中,我们将看到如何查找给定数据框的统计信息。我们将使用summary()函数来获取每列的统计信息:

生成的结果将包含以下详细信息:

  • 最小值 –返回每列的最小值
  • 最大值 –返回每列的最大值
  • Mean –返回每列的平均值
  • Median –返回每列的中位数
  • 第一四分位数 -返回每列的第一四分位数
  • 第三四分位数 -返回每列的第三四分位数。

示例 1:在此示例数据中,我们已获取学生分数、身高、体重和分数,因此我们正在计算这两列的汇总。

R
# create vector with names
name = c("sravan", "mohan", "sudheer", 
         "radha", "vani", "mohan")
  
# create vector with subjects
subjects = c(".net", "Python", "java",
             "dbms", "os", "dbms")
  
# create a vector with marks
marks = c(98, 97, 89, 90, 87, 90)
  
# create vector with height
height = c(5.97, 6.11, 5.89, 5.45, 5.78, 6.0)
  
# create vector with weight
weight = c(67, 65, 78, 65, 81, 76)
  
# pass these vectors to the data frame
data = data.frame(name, subjects,
                  marks, height, weight)
  
# display
print(data)
print("STATISTICAL SUMMARY")
  
# use summary function 
print(summary(data))


R
# create vector with names
name = c("sravan","mohan","sudheer",
         "radha","vani","mohan")
  
# create vector with subjects
subjects = c(".net","Python","java",
             "dbms","os","dbms")
  
# create a vector with marks
marks=c(98,97,89,90,87,90)
  
# create vector with height
height=c(5.97,6.11,5.89,
         5.45,5.78,6.0)
  
# create vector with weight
weight=c(67,65,78,65,81,76)
  
# pass these vectors to the data frame
data=data.frame(name,subjects,marks,
                height,weight)
  
# display
print(data)
print("STATISTICAL SUMMARY of marks")
  
# use summary function  on marks column
print(summary(data$marks))
print("STATISTICAL SUMMARY of height")
  
  
# use summary function on height column
print(summary(data$height))
print("STATISTICAL SUMMARY of weight")
  
# use summary function on weight column
print(summary(data$weight))


R
# create vector with names
name = c("sravan","mohan","sudheer",
         "radha","vani","mohan")
  
# create vector with subjects
subjects = c(".net","Python","java",
             "dbms","os","dbms")
  
# create a vector with marks
marks=c(98,97,89,90,87,90)
  
# create vector with height
height=c(5.97,6.11,5.89,
         5.45,5.78,6.0)
  
# create vector with weight
weight=c(67,65,78,65,81,76)
  
# pass these vectors to the data frame
data=data.frame(name,subjects,marks,
                height,weight)
  
# nature of dataframe
print(paste("names column",class(data$names)))
print(paste("subjects column",class(data$subjects)))
print(paste("marks column",class(data$marks)))
print(paste("height column",class(data$height)))
print(paste("weight column",class(data$weight)))


输出:

示例 2:在此示例中,我们正在获取单个列的统计摘要

电阻

# create vector with names
name = c("sravan","mohan","sudheer",
         "radha","vani","mohan")
  
# create vector with subjects
subjects = c(".net","Python","java",
             "dbms","os","dbms")
  
# create a vector with marks
marks=c(98,97,89,90,87,90)
  
# create vector with height
height=c(5.97,6.11,5.89,
         5.45,5.78,6.0)
  
# create vector with weight
weight=c(67,65,78,65,81,76)
  
# pass these vectors to the data frame
data=data.frame(name,subjects,marks,
                height,weight)
  
# display
print(data)
print("STATISTICAL SUMMARY of marks")
  
# use summary function  on marks column
print(summary(data$marks))
print("STATISTICAL SUMMARY of height")
  
  
# use summary function on height column
print(summary(data$height))
print("STATISTICAL SUMMARY of weight")
  
# use summary function on weight column
print(summary(data$weight))

输出:

查找数据框的性质:

我们可以使用 class()函数来获取数据帧的性质。

它将返回:

  • 数据是否为 NULL
  • 数据框中特定列的数据类型

例子:

电阻

# create vector with names
name = c("sravan","mohan","sudheer",
         "radha","vani","mohan")
  
# create vector with subjects
subjects = c(".net","Python","java",
             "dbms","os","dbms")
  
# create a vector with marks
marks=c(98,97,89,90,87,90)
  
# create vector with height
height=c(5.97,6.11,5.89,
         5.45,5.78,6.0)
  
# create vector with weight
weight=c(67,65,78,65,81,76)
  
# pass these vectors to the data frame
data=data.frame(name,subjects,marks,
                height,weight)
  
# nature of dataframe
print(paste("names column",class(data$names)))
print(paste("subjects column",class(data$subjects)))
print(paste("marks column",class(data$marks)))
print(paste("height column",class(data$height)))
print(paste("weight column",class(data$weight)))

输出: