随笔分类 - R语言
摘要:1、测试数据 a <- c(8,4,7,6,2,5) 2、最大值、最小值 > max(a) [1] 8 > min(a) [1] 2 3、平均数、中位数 > mean(a) [1] 5.333333 > median(a) [1] 5.5 4、方差、标准差 > var(a) [1] 4.666667
阅读全文
摘要:当数据的维度超过2时,可以使用数组。 1、创建数组。2行3列2面的数组 dim1 <- c("a1","a2") dim2 <- c("b1","b2","b3") dim3 <- c("c1","c2") a <- array(1:12,c(2,3,2),dimnames = list(dim1,
阅读全文
摘要:1、 for (i in 1:10) { print("hello,world!") } 2、 for (i in 1:10) { print(i) } 3、 sum = 0 for (i in seq(1,100,1)) { sum = sum + i } print(sum) 4、求二维数组中的
阅读全文
摘要:1、 > a <- c(2,3,4,2,3,4,2,2,4) > b <- as.data.frame(table(a)) > b a Freq 1 2 4 2 3 2 3 4 3
阅读全文
摘要:1、 > a <- c(1,2,2,2,3,1,1,3) > a [1] 1 2 2 2 3 1 1 3 > unique(a) [1] 1 2 3 > duplicated(a) [1] FALSE FALSE TRUE TRUE FALSE TRUE TRUE TRUE > !duplicate
阅读全文
摘要:1、测试数据 > a <- 1:5 > b <- 3:7 > a [1] 1 2 3 4 5 > b [1] 3 4 5 6 7 2、取交集 > a %in% b [1] FALSE FALSE TRUE TRUE TRUE > a[a %in% b] [1] 3 4 5 > intersect(a
阅读全文
摘要:1、测试数据 > a <- c(3,2,2,2,2,2,9,1,4) > b <- c(7,8,4,4,4,6,5,2,3) > c <- c(3,5,7,4,3,2,1,8,6) > d <- data.frame(a, b, c) > d a b c 1 3 7 3 2 2 8 5 3 2 4
阅读全文
摘要:1、 opar <- par(no.readonly = T) par(fig=c(0,0.8,0,0.8)) plot(mtcars$wt,mtcars$mpg) par(fig=c(0,0.8,0.60,1),new= T) boxplot(mtcars$wt,axes = F,horizont
阅读全文
摘要:1、 attach(mtcars) layout(matrix(c(1,1,2,3), 2, 2, byrow=T)) hist(wt) hist(mpg) hist(disp) detach(mtcars) 2、 attach(mtcars) layout(matrix(c(1,2,3,3),2,
阅读全文
摘要:1、 par(mfrow=c(3,2)) plot(1:10) text(1,5,"aa", cex = 2,col = "red") plot(1:10) text(5,5,"bb",cex = 2, col = "blue") plot(1:10) text(5,5, "cc", cex = 2
阅读全文
摘要:1、 > plot(1:10) > locator(1) ## 此时鼠标点击图形中位置,将返回位置坐标 $x [1] 2.202362 $y [1] 7.89666 > text(locator(1),"xxx",cex = 2,col="red") ## 结合text函数,可以图形中添加文本 >
阅读全文
摘要:1、 opar <- par(no.readonly = T) par(mfrow=c(2,2)) plot(1:10) legend("topleft",inset = 0.04,c(paste0("lab", 1:4)),pch = c(15:18), col = c("red","blue",
阅读全文
摘要:1、 plot(1:10) abline(h=5,col="red",lty=2,lwd = 3) 2、 plot(1:10) abline(h=c(2,4,6),col="red",lwd=3) 3、 plot(1:10) abline(v=c(2,4,8), col = "blue", lwd
阅读全文
摘要:1、 library(Hmisc) opar <- par(no.readonly = T) par(mfrow=c(1,2)) plot(1:10) plot(1:10) minor.tick(nx=2,ny=3,tick.ratio = 0.5) par(opar) 2、 library(Hmi
阅读全文
摘要:1、去除外围框线 opar <- par(no.readonly = T) par(mfrow = c(2,1)) plot(1:10) plot(1:10, axes = F) par(opar) 2、去除x轴标线 opar <- par(no.readonly = T) par(mfrow =
阅读全文
摘要:1、随机抽样 > a <- 1:10 > sample(a,5) [1] 9 4 5 10 6 > sample(a,5,replace = T) [1] 10 7 5 3 4 > sample(a,5,replace = T) ## 有放回抽样 [1] 5 9 5 1 3 > b <- LETTE
阅读全文
摘要:1、交集intersect > x <- 1:4 > y <- 3:7 > x [1] 1 2 3 4 > y [1] 3 4 5 6 7 > intersect(x,y) [1] 3 4 2、并集union > x <- 1:4 > y <- 3:7 > x [1] 1 2 3 4 > y [1]
阅读全文
摘要:1、简单用法 > a <- c(5:2,3:7,4+1:4) > a [1] 5 4 3 2 3 4 5 6 7 5 6 7 8 > unique(a) ## 去重复 [1] 5 4 3 2 6 7 8 2、数据框 > a <- rep(1, 5) > b <- c(4,3,2,2,4) > c <
阅读全文
摘要:1、查看系统 [root@centos7 home]# cat /etc/redhat-release CentOS Linux release 7.9.2009 (Core) [root@centos7 home]# hostnamectl Static hostname: centos7 Ico
阅读全文
摘要:1、查看系统 [root@centos8 home]# cat /etc/redhat-release CentOS Linux release 8.3.2011 [root@centos8 home]# hostnamectl Static hostname: centos8 Icon name:
阅读全文

浙公网安备 33010602011771号