R 程序获取给定数据框的统计摘要和数据性质


2023年2月9日, Learn eTutorial
1650

如何获取给定数据框的统计摘要和数据性质

在此我们解释如何编写一个 R 程序来获取给定数据框的统计摘要和数据性质。我们使用内置函数 data.frame(), summary() 来实现。数据框用于存储数据表,其中包含等长向量列表。数据框由函数 data.frame() 创建,它紧密耦合了变量集合。而函数 summary() 有助于生成各种模型拟合函数结果的摘要。此函数的语法是,


summary(object, …) 

其中 dots(...) 是影响生成的摘要的附加参数,object 是需要摘要的对象。

如何在 R 程序中获取给定数据框的统计摘要和数据性质

以下是 R 程序中用于获取给定数据框的统计摘要和数据性质的步骤。在此 R 程序中,我们直接将数据框提供给内置函数。我们使用变量 E, N, S, A, Q 来保存不同类型的向量。调用函数 data.frame() 创建 数据框。最后,通过调用 summary(E) 计算给定数据框的统计摘要。

算法

步骤1:使用向量值为变量ENSAQ赋值

步骤2:首先打印原始向量值

步骤 3:打印给定数据框的统计摘要,如 summary(E)

步骤4:打印最终的数据框

R 源代码

                                          E = data.frame(
N = c('Jhon', 'Hialy', 'Albert', 'James', 'Delma'),
S = c(10, 9.5, 12.2, 11, 8),
A = c(2, 1, 2, 4, 1),
Q = c('yes', 'no', 'yes', 'no', 'no')
)
print("Original dataframe:")
print(E)
print("Statistical summary and nature of the data of the dataframe:")
print(summary(E))
                                      

输出

[1] "Original dataframe:"
     name    score attempts qualify
1  Jhon       10        2     yes
2  Hialy      9.5       1     no
3  Albert     12.2      2     yes
4  James      11        4     no
5  Delma      8         1     no

[1] "Statistical summary and nature of the data of the dataframe:"
      N           S               A       Q    
 Albert:1   Min.   : 8.00   Min.   :1   no :3  
 Delma :1   1st Qu.: 9.50   1st Qu.:1   yes:2  
 Hialy :1   Median :10.00   Median :2          
 James :1   Mean   :10.14   Mean   :2          
 Jhon  :1   3rd Qu.:11.00   3rd Qu.:2          
            Max.   :12.20   Max.   :4