上一页 1 ··· 235 236 237 238 239 240 241 242 243 ··· 367 下一页
摘要: R语言中apply函数,可以实现批量对矩阵、数据框的行或者列进行各种处理。 apply的第一个参数指定操作对象, 第二个参数指定对行还是列进行操作, 第三个参数指定操作类型 1、示例1 a1 <- c(4,2,1,6) a2 <- c(3,2,3,6) a3 <- c(2,1,4,8) dat <- 阅读全文
posted @ 2021-11-01 10:54 小鲨鱼2018 阅读(1239) 评论(0) 推荐(0) 编辑
摘要: R语言中rnorm函数用于产生服从正态分布的随机数。(r:random, norm: normal) 1、直接使用,默认产生平均数为0,标准差为1的随机数。 dat <- rnorm(30) dat mean(dat) sd(dat) 2、可以设定平均数 dat <- rnorm(30,5) ## 阅读全文
posted @ 2021-11-01 10:26 小鲨鱼2018 阅读(7633) 评论(0) 推荐(0) 编辑
摘要: 1、加减(矩阵加减只能在同维度矩阵之间进行,即行列数相同) a1 <- c(2, 3, 5, 1, 7, 4, 8, 4, 2) a2 <- c(3, 1, 3, 1, 4, 8, 4, 3, 4) m1 <- matrix(a1, nrow = 3, byrow = T) m2 <- matrix 阅读全文
posted @ 2021-10-31 21:08 小鲨鱼2018 阅读(1729) 评论(0) 推荐(0) 编辑
摘要: 1、协方差 协方差:两个向量每一项与各自平均数只差 的对应项乘积之和的平均数。 方差:每一项与平均数只差 的平方的平均数。 标准差: 方差开平方 皮尔逊相关系数:两个向量的协方差 除以 两个向量的标准差的乘积。 a <- c(1, 3, 7, 8) b <- c(12, 15, 16, 18) su 阅读全文
posted @ 2021-10-31 19:28 小鲨鱼2018 阅读(2343) 评论(0) 推荐(0) 编辑
摘要: 1、R脚本 dir() dat <- read.table("outcome.ped") dat id <- dat[,2] dat <- dat[, -(1:6)] result <- data.frame() for (i in 1:nrow(dat)) { count = 0 for (j i 阅读全文
posted @ 2021-10-31 18:16 小鲨鱼2018 阅读(126) 评论(0) 推荐(0) 编辑
摘要: 1、shell脚本 [root@centos79 test]# cat test.sh #!/bin/bash ## step1 for i in $(seq `sed -n "$=" $1`); do sed -n "$i"p $1 | cut -d " " -f 7- | grep -o "0" 阅读全文
posted @ 2021-10-31 18:00 小鲨鱼2018 阅读(75) 评论(0) 推荐(0) 编辑
摘要: 1、plink脚本 plink --file outcome --pca 3 header tabs --sheep --out pcatest > /dev/null; rm *.log *.nosex 2、R绘图 dir() dat <- read.table("pcatest.eigenvec 阅读全文
posted @ 2021-10-31 17:00 小鲨鱼2018 阅读(391) 评论(0) 推荐(0) 编辑
摘要: 1、R实现 dir() dat <- read.table("outcome.ped") dim(dat) dat <- dat[,-(1:6)] loci <- data.frame(v1 = rep(1, 2 * nrow(dat))) for (i in 1:(ncol(dat)/2)) { 阅读全文
posted @ 2021-10-31 14:50 小鲨鱼2018 阅读(118) 评论(0) 推荐(0) 编辑
摘要: 1、脚本 [root@centos79 test]# cat test.sh #!/bin/bash #step1 check ped file uniqn=$(sed 's/\r//g' $1 | cut -d " " -f 7- | sed 's/ /\n/g' | sort -u | wc - 阅读全文
posted @ 2021-10-31 12:57 小鲨鱼2018 阅读(98) 评论(0) 推荐(0) 编辑
摘要: 1、脚本只有10行,报第11行错误?? [root@centos79 test]# bash test.sh test.sh: line 11: syntax error: unexpected end of file [root@centos79 test]# cat -n test.sh 1 # 阅读全文
posted @ 2021-10-31 12:20 小鲨鱼2018 阅读(468) 评论(0) 推荐(0) 编辑
上一页 1 ··· 235 236 237 238 239 240 241 242 243 ··· 367 下一页