我正在尝试查找水星的最小值,平均值,中位数,最大值,标准偏差和方差。我不确定如何找到某列。我一直在尝试使用代码data(mean),但无法正常工作。我已附上图片。enter image description here
答案 0 :(得分:1)
您可以尝试使用dplyr
语法的_if
软件包
library(dplyr)
data %>%
summarise_if(is.numeric, funs(mean, sd, var, min, max, median))
我认为这可以满足您的需求。
答案 1 :(得分:0)
您可以对数据框中的列使用dplyr :: summarise()函数:
library(dplyr)
df <- data.frame(
School = c("A R Kaufman Public School", "Abraham Erb Public School", "Alpine Public School", "Avenue Road Public School", "Ayr Public School", "Baden Public School"),
Mercury = c(50, 29, 38, 1, 61, 16),
Lead = c(10, 8, 15, 16, 0, 3),
PCB = c(532, 440, 518, 487, 517, 491),
Arsenic = c(9, 6, 10, 2, 13, 4))
summarise(df, min = min(Mercury),
max = max(Mercury),
mean = mean(Mercury),
median = median(Mercury),
sd = sd(Mercury),
var = var(Mercury))
# min max mean median sd var
# 1 1 61 32.5 33.5 22.02499 485.1