以下是一个比较复杂的R语言代码示例:
# 生成随机数
set.seed(123)
data <- rnorm(1000)
# 数据处理和分析
data_mean <- mean(data)
data_sd <- sd(data)
data_median <- median(data)
# 创建一个绘图窗口
par(mfrow = c(2, 2))
# 绘制直方图
hist(data, main = "Histogram of Data", xlab = "Value", ylab = "Frequency", col = "#55A7E6", border = "white")
# 绘制累积分布曲线
plot(ecdf(data), main = "Empirical Cumulative Distribution", xlab = "Value", ylab = "Cumulative Probability")
# 绘制密度图
density <- density(data)
plot(density, main = "Density Plot", xlab = "Value", ylab = "Density", col = "#FFA500")
# 绘制箱线图
boxplot(data, main = "Boxplot of Data", ylab = "Value", col = "#E6550D", border = "white")
# 输出统计结果
cat("Mean:", data_mean, "\n")
cat("Standard Deviation:", data_sd, "\n")
cat("Median:", data_median, "\n")
这段代码首先生成了一个包含1000个随机数的向量。然后对数据进行统计分析,计算平均值、标准差和中位数。接下来,使用R的绘图函数绘制了四个图形:直方图、累积分布曲线、密度图和箱线图。最后,输出了数据的统计结果。这段代码展示了R语言中数据处理、绘图和统计分析的基本操作。
标签:123,set,示例,代码,seed,随机数,data,mean From: https://blog.51cto.com/u_16018846/7693976