随笔分类 - [31] R
摘要:a = matrix( c(2, 4, 3, 1, 5, 7), # the data elements nrow=2, # number of rows ncol=3, # number of columns byrow = TRUE) # fill matrix by rows class( (
阅读全文
摘要:require(reshape2)x = data.frame(subject = c("John", "Mary"), time = c(1,1), age = c(33,NA), weight = c(90, NA), height = c(2,2))x subject time age wei
阅读全文
摘要:read.csv in R doesn't import all rows from csv file The OP indicates that the problem is caused by quotes in the CSV-file. When the records in the CSV
阅读全文
摘要:union 求两个向量的并集集合可以是任何数值类型union(x=1:3, y=2:5)[1] 1 2 3 4 5union(x=c("abc", "12"), y=c("bcd", "efg"))[1] "abc" "12" "bcd" "efg"setdiff 求向量x与向量y中不同的元素(只取
阅读全文
摘要:Examples: print(match(5, c(1,2,9,5,3,6,7,4,5)))[1] 4 5 %in% c(1,2,9,5,3,6,7,4,5)[1] TRUE 8 %in% c(1,2,9,5,3,6,7,4,5)[1] FALSE > v1 <- c("a1","b2","c1"
阅读全文
摘要:apply() apply(m,dimcode,f,fargs) m 是一个矩阵。 dimcode 是维度编号,取1则为对行应用函数f,取2则为对列运用函数f。 f 是函数 fargs 是函数f的可选参数集 > z <- matrix(1:6, nrow = 3) > f <- function(x
阅读全文
摘要:# Coercing LHS to a list expr_3$ID<-rownames(expr_3) # OK ids<-rownames(expr_3)expr_4<-cbind(expr_3, ID=ids)
阅读全文
摘要:R read.tabe line 5 did not have 2 elements Reason: there are special characters such as # in file old_value new_valueEZF2 ZNF444EZF2 ZNF444ZSCAN17 ZNF
阅读全文
摘要:aa<- list(a=1, b="two", c=list(3, "four"))bb <- list(a=1, c=list(3, "four"), b="ni")aa[!(aa %in% bb)]REF:https://stackoverflow.com/questions/1468856/h
阅读全文
摘要:Say I have a data.frame:df <- data.frame(A=c(10,20,30),B=c(11,22,33), C=c(111,222,333)) A B C1 10 11 1112 20 22 2223 30 33 333If I select two (or more
阅读全文
摘要:d<- data.frame(x = c(0, 1)) d<- data.frame(d, y = c(0,1)) names(d)[2]<- "a.-5" d x a.-50 01 1 d1<- data.frame(d, y = c(0,1)) d1 x a..5 y0 0 01 1 1 d2<
阅读全文
摘要:安装方法一(下载安装;繁琐): 1 下载R源代码原码下载地址https://cloud.r-project.org/https://cloud.r-project.org/src/base/R-3/R-3.4.2.tar.gz2 安装编译环境yum -y install gccyum install
阅读全文
摘要:row.names(x)row.names(x) <- value rownames(x, do.NULL = TRUE, prefix = "row") rownames(x) <- value colnames(x, do.NULL = TRUE, prefix = "col") colname
阅读全文
摘要:https://www.r-bloggers.com/number-formatting/ https://stackoverflow.com/questions/3443687/formatting-decimal-places-in-r https://stat.ethz.ch/R-manual
阅读全文
摘要:ERROR: The estimated pi0 <= 0. Check that you have valid p-values or use a different range of lambda. 重现错误的代码: ps <- runif(3e5)library(qvalue)ps <- ps
阅读全文
摘要:## String comparison is too slow in R language ## it will take 3 minutes, it is too slow date() strArray1<-rep("1234567890",10000) strArray2<-rep("1234567890",10000) tt<-0 for(xx in 1:10000) { ...
阅读全文
摘要:常见与正则表达式相关的函数: 这里是对参数进行一个解释说明。 参数 说明 pattern 正则表达式 x, text 字符向量或字符对象,在R 3.0.0后版本中,最大支持超过2^31个的字符元素。 ignore.case 默认FALSE,表示区分大小写,TRUE时表示不区分大小写。 perl 是否
阅读全文
摘要:1. 文件系统介绍 R语言对文件系统的操作,包括文件操作和目录操作,函数API都定义在base包中。 2. 目录操作 2.1 查看目录 查看当前目录下的子目录。 查看当前目录的子目录和文件。 查看当前目录的子目录和文件,同dir()函数。 查看完整的目录信息。 2.2 创建目录 创建一个3级子目录.
阅读全文
摘要:aaa.R Args <- commandArgs()cat("Args[1]=",Args[1],"\n")cat("Args[2]=",Args[1],"\n")cat("Args[3]=",Args[3],"\n")cat("Args[4]=",Args[4],"\n")cat("Args[5
阅读全文
摘要:When I try converting a matrix to a data frame, it works for me: > x <- matrix(1:6,ncol=2,dimnames=list(LETTERS[1:3],letters[24:25])) > data.frame(x)
阅读全文