NWAFU 生物统计实验二 R语言版

r 复制代码
#1
setwd(修改为你的工作路径或桌面路径)
feed_types <- c("A", "B", "C")
weight_gain_means <- c(36.8, 34.9, 21.3)
weight_gain_sds <- c(2.4, 2.7, 6.6)
weight_gain <- rnorm(3, mean = weight_gain_means, sd = weight_gain_sds)
food_consumption_means <- c(60.5, 56.9, 55.8)
food_consumption_sds <- c(3.1, 2.4, 1.5)
food_consumption <- rnorm(3, mean = food_consumption_means, sd = food_consumption_sds)
weight_food_ratio_means <- c(1.65, 1.64, 2.74)
weight_food_ratio_sds <- c(0.12, 0.13, 0.75)
weight_food_ratio <- rnorm(3, mean = weight_food_ratio_means, sd = weight_food_ratio_sds)
df_feed_stats <- data.frame(feed_types, weight_gain, food_consumption, weight_food_ratio)
#2
data()
df_chick <- ChickWeight
colnames(df_feed_stats)
colnames(df_chick)
df_merge <- merge(df_feed_stats, df_chick)

#3
na.fail(df_merge)
df_clean <- na.omit(df_merge)
names(df_clean)[5] <- 你的名字
library("openxlsx")
write.xlsx(df_clean, file = 你的文件名)  
#4
food_data <- df_clean$food_consumption[1:50]
food_asc <- sort(food_data)
food_desc <- sort(food_data, decreasing = TRUE)
print("升序排序后:")
print(food_asc)
print("降序排序后:")
print(food_desc)
str(df_clean)
r 复制代码
setwd(你的工作目录)
feed <- c("A", "B", "C")
weight_up <- rnorm(3, mean = c(36.8, 34.9, 21.3), sd = c(2.4, 2.7, 6.6))
food <- rnorm(3, mean = c(60.5, 56.9, 55.8), sd = c(3.1, 2.4, 1.5))
weight_food <- rnorm(3, mean = c(1.65, 1.64, 2.74), sd = c(0.12, 0.13, 0.75))
data1 <- data.frame(feed, weight_up, food, weight_food)

data()
chicken<-ChickWeight
colnames(data1)
colnames(chicken)
data2 <- merge(data1, chicken)

na.fail(data2)
data3<-na.omit(data2)
names(data3)[5]<-"你的名字"
library("openxlsx")
write.xlsx(data3, file = "你的文件名")

food_data<-data3$food[1:100]
food_data_sort <- sort(food_data)
food_data_sort
food_data_sort <- sort(food_data,decreasing = T)
food_data_sort
str(data3)
相关推荐
love530love16 小时前
怎么更新 cargo.exe ?(Rust 工具链)
人工智能·windows·python·rust·r语言
烟锁池塘柳04 天前
【R语言】R语言中 rbind() 与 merge() 的区别详解
sql·r语言
夏婵语冰5 天前
实用R语言机器学习指南:从数据预处理到模型实战(附配套学习资源)
开发语言·学习·r语言
Yolo566Q6 天前
“R语言+遥感”的水环境综合评价方法实践技术应用
开发语言·r语言
天意生信云6 天前
生信分析自学攻略 | R语言数据筛选和修改
数据结构·经验分享·r语言
烟锁池塘柳08 天前
【R语言】R 语言中 gsub 与正则表达式详解(含 POSIX 与 Perl 风格实例)
正则表达式·r语言·perl
梦想的初衷~9 天前
“R+遥感”的水环境综合评价方法实践技术应用
r语言·水环境·水文
天意生信云10 天前
生信分析自学攻略 | R软件和Rstudio的安装
经验分享·r语言
TS的美梦10 天前
【1:1复刻R版】python版火山图函数一键出图
开发语言·python·r语言·scanpy·火山图
nonono10 天前
深度学习——R-CNN及其变体
深度学习·r语言·cnn