R语言练习代码是怎样写的
发表于:2025-02-11 作者:千家信息网编辑
千家信息网最后更新 2025年02月11日,这篇文章给大家介绍R语言练习代码是怎样写的,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。x <- c(1:10)x <- c(v1 = 1:4,v2 = 10:14)instal
千家信息网最后更新 2025年02月11日R语言练习代码是怎样写的
这篇文章给大家介绍R语言练习代码是怎样写的,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
x <- c(1:10)x <- c(v1 = 1:4,v2 = 10:14)install.packages()install.packages("xlsx")install.packages("rJava")install.packages("xlsxjars")install.packages("vcd").libPaths()install.packages(c("AER","ca"))library()library(xlsx)library(rJava)print()require(vcd)require(xlsx)installed.packages()installed.packages()[,1]Rpack <- installed.packages()[,1]save(Rpack,file = "Rpack.Rdata")for (i in Rpack) install.packages(i)help.xlsx()help.start()x <- read.csv("碧彩测试数据1.07",header = TRUE)y <- readClipboard()read.table("clipboard",sep = ",",header = TRUE)read.table("clipboard",sep = "\t",header = TRUE)install.packages("arules")data(Groceries)Groceriesa <- c(100,rep(10,4))mean(a)b <- c(1000,rep(50,9),rep(5,5))sum(b)A <- c(1,2,5,8,9)jicha <- max(A) - min(A)jichafangcha <- function(x){return(sum((x-mean(x))^2)/length(x))}fangchafangcha(A)install.packages("moments")library("moments")data1x <- read.csv("C:\\Users\\QDM\\Desktop\\销售业绩.csv",header = T)xy <- read.table("C:\\Users\\QDM\\Desktop\\销售业绩.txt",header = T)yz <- read.table("clipboard",header = T,sep = "\t")z1+3x <- c(1,3,8,4,7,5,6,1)png(file = "barchart.png")barplot(x)dev.off()x <- read.table("clipboard",header = T,sep = "\t")xx <- read.table("clipboard",header = T)xbarplot(apply(x,1,mean))barplot(apply(x,2,median))pie(apply(x,2,mean))barplot(height = 1:10)data <- cbind(a = 1:4, b = 1:4)barplot(data)data <- cbind(a = 1:4, b = 1:4)barplot(data, beside = T)barplot(1:5, width = 5:1)barplot(1:3, space = c(0.1, 0.2, 0.3))par(mfrow = c(1, 2))height <- c(1:3)names(height) <- c("A", "B", "C")barplot(height)data <- cbind("A" = 1:4, "B" = 1:4)barplot(data)par(mfrow = c(1, 2))height <- c(1:3)names(height) <- c("A", "B", "C")barplot(height, names.arg = c("A1", "A2", "A3"))data <- cbind("A" = 1:4, "B" = 1:4)barplot(data, names.arg = c("D", "E"))data <- cbind(a = 1:4, b = 1:4)rownames(data) <- c("A", "B", "C", "D")barplot(data, legend.text = TRUE)data <- cbind(a = 1:4, b = 1:4)rownames(data) <- c("A", "B", "C", "D")barplot(data, legend.text = c("E", "F", "G", "H"))par(mfrow = c(1, 2))data <- cbind(a = 1:4, b = 1:4)barplot(data, main = "beside = F")barplot(data, beside = T, main = "beside = T")par(mfrow = c(1, 2))barplot(1:4, main = "horiz = F")barplot(1:4, main = "horiz = T", horiz =T)barplot(1:4, col = "green")barplot(1:4, col = rainbow(4))barplot(1:4, col = rainbow(4), border = NA, main = "border = NA")par(mfrow = c(1, 3))barplot(rep(1,4), density = 1, main = "density = 1")barplot(rep(1,4), density = 2, main = "density = 2")barplot(rep(1,4), density = 3, main = "density = 3")par(mfrow = c(1, 3))barplot(rep(1,4), density = 2, angle = 45, main = "angle = 45")barplot(rep(1,4), density = 2, angle = 90, main = "angle = 90")barplot(rep(1,4), density = 2, angle = 180, main = "angle = 180") par(mfrow = c(1, 2))data <- cbind(a = 1:4, b = 1:4)barplot(data, axes = F, main = "axes = F")barplot(data, axes = T, main = "axes = T")par(mfrow = c(1, 2))data <- cbind(a = 1:4, b = 1:4)barplot(data, axisnames = F, main = "axisnames = F")barplot(data, axisnames = T, main = "axisnames = T")par(mfrow = c(1, 3))data <- cbind(a = 1:4, b = 1:4)barplot(data, offset = 0, main = "offset = 0")barplot(data, offset = 1, main = "offset = 1")barplot(data, offset = 2, main = "offset = 2")barplot(1:4, col = rainbow(4), border = NA, main = "border = NA")barplot(height = 1:7)barplot(height = 1:7,beside = T, main = "2020年5月份业绩")barplot(height = 1:7,beside = T, main = "2020年5月份业绩",col = rainbow(7))barplot(height = 1:7,beside = T, main = "2020年5月份业绩",col = rainbow(7),border = NA)barplot(height = 1:7,beside = T, main = "2020年5月份业绩",col = rainbow(7),border = NA)QDM <- read.table("clipboard",header = T)QDMQDM <- c(100,200,300,400,500,600)depatment <- c("电商","水产","水果","蔬菜","肉类","综合")barplot(QDM,names.arg = depatment)barplot(QDM,names.arg = depatment,col = "green")barplot(QDM,names.arg = depatment,col = "red")barplot(QDM,names.arg = depatment,col = "blue")barplot(QDM,names.arg = depatment,col = "black")barplot(QDM,names.arg = depatment,col = "pink")barplot(QDM,names.arg = depatment,beside = T, main = "2020年5月份各部门业绩",col = rainbow(7))barplot(QDM,names.arg = depatment,beside = T, main = "2020年5月份各部门业绩",col = rainbow(7),border = NA)data <- c(60,70,80,90,100)barplot(data)data1 <- c(60,70,80,90,100)bumen <- c("水产","水果","蔬菜","猪肉","综合")barplot(data1,names.arg = bumen)barplot(y,names.arg = x,border = NA,xlab = "部门",ylab = "销售额",main = "2020年5月份各部门总销售额",col = rainbow(4))barplot(y,names.arg = x,border = "blue",xlab = "部门",ylab = "销售额",main = "2020年5月份各部门总销售额",col = rainbow(4))x <- c(1020,1640,1340,1610,1942)xy <- c("水产","水果","蔬菜","猪肉","综合")yplot(x,names.arg = y)barplot(x,names.arg = y,border = NA)barplot(x,names.arg = y,border = NA,col = rainbow(5))plot(x,names.arg = y,type = "b")plot(x,names.arg = y,type = "b",col = "red")plot(x,names.arg = y,type = "b",col = "green")plot(x,names.arg = y,type = "b",col = "DarkTurquoise")n <- 6pie(x,n)pie(x,y,border = NA)pie(x,y,border = NA,col = rainbow(7))pie(x,y,col = rainbow(7))piecolors <- rainbow(n)piecolorspie(x,y,border = "gray",col = rainbow(7))a <- c(100,150,130,168,111)pie(a,y)x <- c(1,2,3,4,5,6,7)y <- c("周一","周二","周三","周四","周五","周六","周日")barplot(x,names.arg = y)barplot(x,names.arg = y,col = rainbow(7))barplot(x,names.arg = y,col = rainbow(7),border = NA)pie(x,y)pie(x,y,col = brewer.pal(7,"Set1"))write.table(x,file = "result.txt", sep = "\t", quote = FALSE)x <- read.table("clipboard",header = T,sep = "\t")xy <- read.csv("出入库.csv",header = TRUE)yls("package:graphics")x <- c(1:4)y <- c(4:6)arrows(x,y)stars(x)box(x)demo(graphics)help(package = "graphics")example("heatmap")example("barplot")example("pie")pie(rep(1, n), labels = "", col = rainbow(n), border = NA, pie+ main = "pie(*, labels=\"\", col=rainbow(n), border=NA,..")pie(c(Sky = 78, "Sunny side of pyramid" = 17, "Shady side of pyramid" = 5), pie+ init.angle = 315, col = c("deepskyblue", "yellow", "yellow3"), border = FALSE)pie> pie(c(Sky = 78, "Sunny side of pyramid" = 17, "Shady side of pyramid" = 5), pie+ init.angle = 315, col = c("deepskyblue", "yellow", "yellow3"), border = FALSE)example("boxplot")womenplot(women)barplot(women$height)barplot(women$height,women$weight)plot("fit")methods(plot)methods(print)par()barplot(height = 1:3,col = c("red","green","blue"))barplot(height = 1:3,col = c("red","green","blue"),border = NA)plot(women$height,women$weight)fit <- lm(height ~ weight,data = women)fitsummary(fit)install.packages("ggplot2")?ggplot2?barplotinstall.packages("caret")library("caret")library(caret)data()carswomenGermanCreditGermanCreditGermanCredit?piex <- c("蔬菜","水果","水产","猪肉","综合")xy <- c(5,4,3,2,1)ypie(y,labels = names(x))pie(y,labels = names(x),col = rainbow(5))pie(y,labels = names(x),col = rainbow(5),border = NA)pie(y,labels = names(x),col = rainbow(5),border = NA,edges = 200)pie(y,labels = names(x),col = rainbow(5),border = NA,edges = 10)pie(y,labels = names(x),col = rainbow(5),border = NA,radius = 1)pie(y,labels = names(x),col = rainbow(5),border = NULL,radius = 1)pie(y,labels = names(x),col = rainbow(5),border = "white",radius = 1)pie(y,labels = names(x),col = rainbow(5),border = NULL,radius = 1,main = "滕玉龙")pie(y,labels = names(x),col = rainbow(5),border = NULL,radius = 1, angle = 45)pie(y,labels = names(x),col = rainbow(5),border = NULL,radius = 1, clockwise = TRUE)pie(y,labels = names(x),col = rainbow(5),border = NA,radius = 1, clockwise = TRUE)pie(y,labels = names(x),col = rainbow(5),border = NA,radius = 1, clockwise = TRUE,main = "滕玉龙")example(pie)pie(y,names(x) <- c("蔬菜","水果","水产","猪肉","综合") ,col = rainbow(5),border = NA,radius = 1, clockwise = TRUE,main = "7月份各部门销售占比")library("ggplot2")qplot(Wind,Temp,data = airquality)qplot(Wind,Temp,data = airquality,color = Month)qplot(Wind,Temp,data = airquality,color = I("blue"))qplot(Wind,Temp,data = airquality,shape = Month)qplot(Wind,Temp,data = airquality,size = Month)qplot(Wind,Temp,data = airquality,size = I(15))qplot(Wind,Temp,data = airquality,size = I(10),color = I("red"),xlab = "风速",ylab = "气温",main = "气温与风速的关系")qplot(Wind,Temp,data = airquality,size = I(10),color = I("red"),xlab = "风速",ylab = "气温",main = "气温与风速的关系",fill = Month)qplot(Wind,data = airquality,fill = Month)qplot(Wind,data = airquality,geom = "density")qplot(Wind,data = airquality,geom = "density",color = Month)qplot(Wind,data = airquality,geom = "dotplot",color = I("green"))df = data.frame(x=1:10, y=seq(1, 20, 2), z=seq(1000, 100, -100), c=paste("color", seq(1, 10, 1)))dfinstall.packages("ggplot2") # 安装包install.packages("RColorBrewer")library(ggplot2) # 加载包library(RColorBrewer)ggplot(df, aes(x=x, y=y)) + geom_bar(stat="identity")ggplot(df, aes(x=x, y=y, fill=c)) + geom_bar(stat="identity") + labs(x="x axis", y="y axis", fill="legend")ggplot(df, aes(x=x, y=y, fill=x)) + geom_bar(stat="identity") + labs(x="x axis", y="y axis", fill="legend")ggplot(df, aes(x=x, y=y, fill=z)) + geom_bar(stat="identity") + labs(x="x axis", y="y axis", fill="legend")colors <- colorRampPalette(c("red", "orange"))(10)colors# [1] "#FF0000" "#FF1200" "#FF2400" "#FF3700" "#FF4900" "#FF5B00" "#FF6E00" "#FF8000" "#FF9200" "#FFA500"ggplot(df, aes(x=x, y=y)) + geom_bar(stat="identity", fill=colors[rank(10:1)]) + labs(x="x axis", y="y axis", fill="legend")ggplot(df, aes(x=x, y=y)) + geom_bar(stat="identity", fill=brewer.pal(10, "Set3")) + labs(x="x axis", y="y axis", fill="legend")?data.frame?barplotgoods <- c("豆芽","茄子","淮山","番茄","芋头","土豆","萝卜","马蹄","莴笋","红薯")goodsamountbarplot(height = 1:10,col = rainbow(10),border = NA,names.arg = goods,main = "各种农产品的产量(单位:万吨)\n\nMade By 滕玉龙",sub = "左手Python,右手R语言",ylab = "产量(万吨)",xlab = "农产品名称")amount <- c(100, 130, 169, 220, 286, 372, 484, 629, 818, 1063)amountbarplot(height = amount,col = rainbow(10),border = NA,names.arg = goods,main = "各种农产品的产量(单位:万吨)\n\nMade By 滕玉龙",sub = "左手Python,右手R语言",ylab = "产量(万吨)",xlab = "农产品名称")grade <- c("大一", "大二", "大三", "大四")amount <- c(15, 38, 123, 35)barplot(height = amount,col = rainbow(4),border = NA,names.arg = grade,main = "各年级发生的频次",sub = "哈佛在等我呢~",ylab = "频次",xlab = "年级")
关于R语言练习代码是怎样写的就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
月份
业绩
销售
水产
水果
蔬菜
综合
语言
产量
农产
农产品
气温
猪肉
销售额
风速
玉龙
代码
内容
单位
右手
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
教育类的软件开发加班严重吗
汝州软件开发有限公司
武汉豪情猫网络技术有限公司
迷雾下载软件开发
网络安全周主题团课
鼎秀数据库文献引用格式
dhcp网络技术大题
商场管理软件开发代码
软件开发国军标
app系统软件开发费用标准
天融信网络技术有限公司股票
大数据炒股软件开发
学网络技术有什么
虹口区品牌软件开发信息中心
服务器加载不了程序
悬镜服务器和安全狗
龙岗手机软件开发哪家技术好
网络安全审计员述职
小三相电机绕组数据库
数据库小抄
数据库默认用户是指什么
网络安全学试题及答案
湖州公司网络安全
t630服务器显卡
国家网络安全立法核心
mt5怎么添加服务器
软件开发去哪个翰诺科技好
虚拟服务器安全吗
一数据库一个binlog文件
罗村软件开发培训比较好