Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
根据R中的数据类型生成摘要/表统计信息_R - Fatal编程技术网

根据R中的数据类型生成摘要/表统计信息

根据R中的数据类型生成摘要/表统计信息,r,R,我想在R中编写一个自动代码来生成摘要和表 基于数据类型的变量统计信息。对于e、 g If data type = Numeric, display summary(); If data type = factor, display table(); 请帮帮我 谢谢 巴拉吉这应该可以 data <- data.frame(a=rnorm(4), b=c("a", "a", "b", "b"), c=c(TRUE, FALSE, TRUE, FALSE)) Display <- f

我想在R中编写一个自动代码来生成摘要和表

基于数据类型的变量统计信息。对于e、 g

If data type = Numeric, display summary();

If data type = factor, display table();
请帮帮我

谢谢 巴拉吉

这应该可以

data <- data.frame(a=rnorm(4), b=c("a", "a", "b", "b"), c=c(TRUE, FALSE, TRUE, FALSE))

Display <- function(x) {
    switch(
    EXPR = class(x),
    factor = {
       print(table(x))
    },
    numeric = {
       print(summary(x))
    },
    print("not supported type")
    )
 }

 Display(data$a)
 Display(data$b)
 Display(data$c)
您需要的数据
if(is.numeric(x)){…}else if(is.factor(x)){…}else{…}
。还有别的事吗?