摘要: # 因子的使用 ------------------------------------------------------------------- diabetes <- factor(diabetes) View(diabetes) status <- c('Poor','Improved','Excellent','Poor') status <- factor(status, or... 阅读全文
posted @ 2019-09-11 14:10 dogfaraway 阅读(157) 评论(0) 推荐(0) 编辑
摘要: # 列表 ##list创建列表 g = 'My First List' h = c(25,26,18,39) j = matrix(1:10, nrow = 5) j str(j) k = c('one','two','three') mylist = list(title = g, ages = h,j,k) mylist str(mylist) mylist[1] mylist['ages'] 阅读全文
posted @ 2019-09-11 14:10 dogfaraway 阅读(117) 评论(0) 推荐(0) 编辑
摘要: # 选取数据框中的元素 --------------------------------------------------------------- patientdata[c('diabetes','status')] patientdata[1:2] patientdata[,1:2] patientdata$age table(patientdata$diabetes,patient... 阅读全文
posted @ 2019-09-11 14:09 dogfaraway 阅读(253) 评论(0) 推荐(0) 编辑
摘要: # 数据框 --------------------------------------------------------------------- patientID = c(1,2,3,4) age = c(25,34,28,52) diabetes <- c('Type1','Type2','Type1','Type2') status <- c('Poor','Improved','... 阅读全文
posted @ 2019-09-11 14:07 dogfaraway 阅读(130) 评论(0) 推荐(0) 编辑
摘要: # 数组 ##创建一个数组 dim1 = c('A1','A2') dim2 = c('B1','B2','B3') dim3 = c('C1','C2','C3',"C4") z <- array(1:24,c(2,3,4), dimnames = list(dim1,dim2,dim3)) z <- array(1:24,c(2,3,4), dimnames = list(c('A1','A2 阅读全文
posted @ 2019-09-11 14:07 dogfaraway 阅读(101) 评论(0) 推荐(0) 编辑
摘要: 快速让你的R代码变得漂亮易读 1. 一般性规则 尽量避免使用attach Error应该使用Stop来停止 S3和S4的函数不要一起使用 尽量避免使用attach Error应该使用Stop来停止 S3和S4的函数不要一起使用 2. 命名 文件名,以 .R结尾,赋予意义 e.g.:predict_a 阅读全文
posted @ 2019-09-11 14:01 dogfaraway 阅读(821) 评论(0) 推荐(0) 编辑
摘要: Google's R Style Guide R is a high-level programming language used primarily for statistical computing and graphics. The goal of the R Programming Sty 阅读全文
posted @ 2019-09-11 13:52 dogfaraway 阅读(476) 评论(0) 推荐(0) 编辑
摘要: # 矩阵 ##创建矩阵 y <- matrix(1:20, nrow = 4, ncol=4) det(y) y cells <- c(1,26,24,66) cells rnames <- c('R1','R2') rnames cnames <- c('C1','C2') cnames mymatrix = matrix(cells,nrow = 2,ncol = 2,byrow = TRUE 阅读全文
posted @ 2019-09-11 12:34 dogfaraway 阅读(128) 评论(0) 推荐(0) 编辑
摘要: # 向量 ##组合函数c()创建向量 a <- c(1,2,5,3,6,-2,4) #数值型 b<- c('one',"two",'three') #字符型 c <- c(TRUE,TRUE,F,T,F) #逻辑型 # 标量,只含有一个元素的向量,例如 f <- 3 a[3] a[-1] a[c(-1,3,5)] a[0] #numeric(0) 没有值 a[2:6] 阅读全文
posted @ 2019-09-11 12:30 dogfaraway 阅读(448) 评论(0) 推荐(0) 编辑
摘要: # 数据集的概念 ------------------------------------------------------------------ ##对“列”的叫法不同 ##统计学:观测observation,或变量variable ##数据库:记录record,或字段field ##数据挖掘/机器学习:示例example,属性attribute 阅读全文
posted @ 2019-09-11 12:28 dogfaraway 阅读(326) 评论(0) 推荐(0) 编辑