随笔分类 - R语言
摘要:001、测试数据 root@PC1:/home/test3# ls test.gff root@PC1:/home/test3# cat test.gff ## 测试数据 a b c e j j a b c i j k a b c x y z i q m x y z i e i 002、unique
阅读全文
摘要:001、测试数据 root@PC1:/home/test3# ls test.gff root@PC1:/home/test3# cat test.gff ## 1 aa bb xx yy ## 2 jj kk uu ss ee 3 mm jj aa ww ff 4 ee ww qq kk ee 5
阅读全文
摘要:001、测试数据 root@PC1:/home/test3# ls test.gff root@PC1:/home/test3# cat test.gff 1 aa bb xx yy 2 jj kk uu ss 3 mm jj aa ww 4 ee ww qq kk 5 xx ff ee jj di
阅读全文
摘要:001、测试数据 root@PC1:/home/test3# ls test.gff root@PC1:/home/test3# cat test.gff aa bb xx yy jj kk mm ee ww qq kk uu xx ff ee dir() dat1 <- read.table("t
阅读全文
摘要:001、 2 * pt(-abs(0.6751), df = 287, lower.tail= T) ## T值为0.6751, 自由度为287 2 * pt(-abs(0.6751), df = 287, lower.tail= F)
阅读全文
摘要:001、 pchisq(0.971, 1, lower.tail = F) ## 卡方值为0.971,自由度1,计算P值 pchisq(0.971, 1, lower.tail = T)
阅读全文
摘要:001、 dat <- read.table("test.txt") dat idx <- vector() for (i in 1:nrow(dat)) { if ("AKCR02000001" %in% dat[i,]) { idx <- c(idx, i) } } idx dat[idx,]
阅读全文
摘要:001、next(相当于continue, 跳过次轮循环) for (i in 1:5) { if (i %% 2 == 0) {next} ## 当i为偶数时,跳过次轮循环 cat(i,"test\n") } 002、break,终止当前程序 for (i in 1:5) { if (i %% 2
阅读全文
摘要:001、 a <- c(3, 4, 8, 7, 2) b <- c(2, 4, 5, 8, 9) c <- 1:5 dat <- data.frame(a, b, c) ## 测试数据框 dat dimnames(dat) ## 返回2元素列表, 1储存行名, 2存储列名 002、 a <- c(3
阅读全文
摘要:001、 a <- c(3, 4, 8, 7, 2) b <- c(2, 4, 5, 8, 9) c <- 1:5 dat <- data.frame(a, b, c) ## 生成测试数据框 dat d <- dat[1,2] ## 默认 class(d) e <- dat[1,2, drop =
阅读全文
摘要:001、 regexpr("x", "edxerr") ## 返回匹配字符串的索引 regexpr("x", "edxerxr") ## 仅匹配第一个匹配到的字符串 002、 gregexpr("x", "edxerr") ## 返回匹配字符串的索引 gregexpr("x", "edxerxr")
阅读全文
摘要:001、 test <- "erijk" temp <- unlist(strsplit(test, split = "")) ## 把字符串拆分为字符 rev(temp) paste(rev(temp), collapse = "") ## 逆转并合并 002、 test <- "akujm" #
阅读全文
摘要:001、R语言中utf8ToInt函数用于将UTF8值转换为整数值 utf8ToInt("a") ## 函数的参数为字符串 utf8ToInt("b") utf8ToInt("d") utf8ToInt("abcd") 002、逆向转换 intToUtf8(97) ## 数值转换为字符 intToU
阅读全文
摘要:001、 start <- Sys.time() ## 记录时间 Sys.sleep(70) ## 程序运行 end <- Sys.time() ## 记录时间 difftime(end, start, units = "sec") ## 以秒表示 difftime(end, start, unit
阅读全文
摘要:001、 test <- "jEnMqAb" ## 测试字符串 newstr <- "" for (i in 1:nchar(test)) { if (i == 1){ newstr <- paste0(newstr, toupper(substr(test, 1, 1))) } else { ne
阅读全文
摘要:001、 test <- "jjUUaaBiJJ" ## 测试字符串 newstr <- "" for (i in 1:nchar(test)) { if (substr(test, i, i) %in% letters) { newstr <- paste0(newstr, toupper(sub
阅读全文
摘要:001、 test <- "xx aa yy zz" ## 测试字符串 strsplit(test, split = " ") ## split = 用于指定分割的依据, 此处设定为空格 strsplit(test, split = "") ## 指定分割依据为空白 strsplit(test, N
阅读全文
摘要:001、 test <- "jknmq" ## 测试字符串 test temp <- rev(unlist(strsplit(test, NULL))) ## 逆向输出为字符 temp paste(temp, collapse = "") ## 合并为字符串 002、 test <- "jknmq"
阅读全文
摘要:001、 test <- c("i", "j", "a", "k", "q") ## 测试字符向量 test paste(test, collapse = "") ## 利用paste合并为一个完整的字符串
阅读全文
摘要:001、 test <- "dsrrf" nchar(test) ## 统计字符串test的长度 002、应用于字符串向量 test <- c("ewr", "e", "ew", "werer") nchar(test)
阅读全文

浙公网安备 33010602011771号