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)
data( )
df_chick <- ChickWeight
colnames( df_feed_stats)
colnames( df_chick)
df_merge <- merge( df_feed_stats, df_chick)
na.fail( df_merge)
df_clean <- na.omit( df_merge)
names( df_clean) [ 5 ] <- 你的名字
library( "openxlsx" )
write.xlsx( df_clean, file = 你的文件名)
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)
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)