随笔分类 -  R语言

上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 27 下一页
摘要:001、rev函数逆向输出向量 test <- c("ewsf", "dsrfe", "iuuyy") test class(test) rev(test) ## 逆向输出 test2 <- 1:5 test2 rev(test2) ## 逆向输出 002、应用数数据框 a <- c(3, 5, 2 阅读全文
posted @ 2022-07-07 09:33 小鲨鱼2018 阅读(1423) 评论(0) 推荐(0)
摘要:001、直接输入函数 library(qqman) ## 加载包 manhattan ## 直接再终端输入函数名称回车,即可显示源代码 002、在Rstudio中,在终端中选中函数, 按f2 library(qqman) manhattan ## 选中函数名, 按f2 003、fix(函数名)或者 阅读全文
posted @ 2022-06-30 19:10 小鲨鱼2018 阅读(2887) 评论(0) 推荐(0)
摘要:001、 a <- c(3, 4, 3, 1) b <- c(1, 2, 5, 4) c <- c(3, 1, 2, 7) dat <- data.frame(a, b, c) dat colSums(dat) ## 求和 rowSums(dat) colMeans(dat) ## 平均值 rowM 阅读全文
posted @ 2022-06-30 16:43 小鲨鱼2018 阅读(1322) 评论(0) 推荐(0)
摘要:001、 packages <- c("data.table", "ggplot2", "qqman", "detectRUNS") ## 确保包已经安装 sapply(packages, require) sapply(packages, require, character.only = TRU 阅读全文
posted @ 2022-06-30 14:39 小鲨鱼2018 阅读(170) 评论(0) 推荐(0)
摘要:001、应用于数据框 a <- c(2, 3, 6) b <- c(5, 2, 2) c <- c(4, 5, 1) dat <- data.frame(a, b, c) dat sapply(dat, sum) ## 对列进行循环, 求和, 返回向量 002、应用于列表 a <- c(3, 4, 阅读全文
posted @ 2022-06-30 12:31 小鲨鱼2018 阅读(919) 评论(0) 推荐(0)
摘要:001、substr str <- "werewrt" ## 测试字符串 substr(str, 1, 3) ## 提取1-3字符 substr(str, 3) ## 必须指定起始 substr(str, 2, 2) ## 提取单个字符 002、substring str <- "werewrt" 阅读全文
posted @ 2022-06-30 12:21 小鲨鱼2018 阅读(1098) 评论(0) 推荐(0)
摘要:001、 dir() ## 直接输出 pdf("001.pdf") plot(1:10, xlab = "测试") dev.off() library(sysfonts) ## 给输出的pdf文件增加中文 library(showtext) font_add("myFont1", "timesbd. 阅读全文
posted @ 2022-06-29 17:46 小鲨鱼2018 阅读(820) 评论(0) 推荐(0)
摘要:001、加载包测试 library(data.table) library(ggplot2) library(dplyr) library(Seurat) library(patchwork) 002、批量安装R包 packages <- c("data.table", "ggplot2", "dp 阅读全文
posted @ 2022-06-28 21:19 小鲨鱼2018 阅读(423) 评论(0) 推荐(0)
摘要:001、 root@PC1:/home/test3# cat a.txt 1 2 3 4 5 root@PC1:/home/test3# cat b.txt test01 test02 test03 test04 test05 root@PC1:/home/test3# cat test.r lib 阅读全文
posted @ 2022-06-22 17:34 小鲨鱼2018 阅读(131) 评论(0) 推荐(0)
摘要:001、 dir() ped1 <- read.table("test.ped") ped1 ped2 <- read.table("test.ped", colClasses = "character") ## 增加该参数 ped2 阅读全文
posted @ 2022-06-22 15:58 小鲨鱼2018 阅读(148) 评论(0) 推荐(0)
摘要:1、提取 包含s的列 dir() dat <- read.table("a.txt") dat ## 测试数据 idx <- dat[1,] == "s" idx for (i in 2:nrow(dat)) { temp <- dat[i,] == "s" idx <- idx | temp ## 阅读全文
posted @ 2022-06-16 10:00 小鲨鱼2018 阅读(546) 评论(0) 推荐(0)
摘要:1、 dat <- matrix(c(3, 7, 1, 2, 4, 9, 8, 5, 0, 15, 22, 77, 11, 44, 33, 88), nrow = 4) dat lines <- nrow(dat) * (nrow(dat) - 1)/2 + nrow(dat) lines res 阅读全文
posted @ 2022-06-15 21:09 小鲨鱼2018 阅读(231) 评论(0) 推荐(0)
摘要:1、系统信息 root@ubuntu2204test01:/home# lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 22.04 LTS Release: 22.04 C 阅读全文
posted @ 2022-06-14 10:54 小鲨鱼2018 阅读(1048) 评论(0) 推荐(0)
摘要:001、 a = NA ## NA表示这个位置的值为空 b = "" ## ""表示空字符串 c = NULL ## NULL表示变量为空 a b c class(a) ## 逻辑类型 class(b) ## 字符类型 class(c) ## NULL类型 length(a) ## 长度为1 len 阅读全文
posted @ 2022-06-08 12:31 小鲨鱼2018 阅读(1841) 评论(0) 推荐(0)
摘要:001、 函数原型: %||%函数一共有两个参数: 当x为空时,返回y, x不为空时,返回x。 library(rlang) 1 %||% 2 NULL %||% 2 ## 这里的空值只识别 NULL。 "" %||% 2 NA %||% 2 阅读全文
posted @ 2022-06-08 12:10 小鲨鱼2018 阅读(604) 评论(0) 推荐(0)
摘要:判断逻辑向量是否至少一个为真或者全部为真。 1、 any(c(FALSE, FALSE, FALSE)) ## 任何一个为真,则为真 any(c(FALSE, FALSE, TRUE)) any(c(TRUE, TRUE, TRUE)) all(c(TRUE, TRUE, TRUE)) ## 全部为 阅读全文
posted @ 2022-06-08 11:56 小鲨鱼2018 阅读(1821) 评论(0) 推荐(1)
摘要:001、 switch ("a", ## 匹配a "a" = 1:5, "b" = 3:8, "c" = 100-110 ) switch ("b", ## 匹配b "a" = 1:5, "b" = 3:8, "c" = 100-110 ) switch ("c", ## 匹配c "a" = 1:5 阅读全文
posted @ 2022-06-08 11:27 小鲨鱼2018 阅读(1689) 评论(0) 推荐(0)
摘要:1、 直接看例子 a <- c(3, 5, 3, 1, 4, 2) b <- c(10, 50, 60, 70, 80, 40) c <- c("a", "a", "b", "b", "c", "c") dat <- data.frame(a, b, c) dat ## 测试数据 tapply(da 阅读全文
posted @ 2022-06-07 20:07 小鲨鱼2018 阅读(1125) 评论(0) 推荐(0)
摘要:1、c函数实现 dat <- matrix(sample(1:9, 15, replace = T), nrow = 3) dat c(dat) ## 逐列转换为向量 c(t(dat)) ## 逐行转换为向量 2、for循环实现 dat <- matrix(sample(1:9, 15, repla 阅读全文
posted @ 2022-06-07 15:22 小鲨鱼2018 阅读(2007) 评论(0) 推荐(0)
摘要:1、 a <- runif(10) ## 在0到1之间取出10个复合均匀分布的随机数 b <- sample(1:3, 10, replace = T) ## 在1-3中取出10个随机数 a b split(a, b) ## 对a按照b为列表名进行归类 阅读全文
posted @ 2022-06-07 14:01 小鲨鱼2018 阅读(82) 评论(0) 推荐(0)

上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 27 下一页