如何找到 r 中数据集中所有变量的最大值、最小值、平均值、第 5、第 10 个百分位数

How to find max, min, mean, 5th,10th Percentile for all the variables in the dataset in r

如何找到数据集中所有变量的最大值、最小值、平均值、第 5 个、第 10 个百分位数。函数 colMax()colMin() 在我的 R(3.5 版)中不起作用,apply(dat, MARGIN = 2, function(x) min(x, na.rm=TRUE))apply(dat,2,min, na.rm=TRUE) 没有为所有变量提供正确的结果(为某些变量提供正确的结果(列))当我用 min(dat$col1 ,na.rm=TRUE) 交叉验证时。使用 colMeans(dat, na.rm=TRUE) 查找均值,但我的数据(文件名)包含字符类型变量,现在需要通过忽略字符变量来仅查找数字变量的均值。谢谢

我认为这会有所帮助:

#Sample data
data("iris")
iris
Data <- iris[,-5]
#Compute
compute <- function(x)
{
  max <- max(x, na.rm=T)
  min <- min(x, na.rm=T)
  meanv <- mean(x, na.rm=T)
  q5 <- quantile(x, 0.05)
  q10 <- quantile(x, 0.10)
  ent <- data.frame(max=max, min=min, meanv=meanv, q5=q5, q10=10)
  rownames(ent) <- NULL
  return(ent)
}
apply(Data, 2, compute)