摘要: 求解上述递归求和,有两种实现方式, 如图所示,从第一个元素开始, def arrSum_fwd(arr): arrLen = len(arr) if arrLen == 0: return 0 else: return arr[0] + arrSum(arr[1:arrLen]) arrSum_fw 阅读全文
posted @ 2020-01-15 22:50 dogfaraway 阅读(318) 评论(0) 推荐(0) 编辑
摘要: 例如,有1~8,查找其中的一个数, 如果采用简单查找,也就是遍历方法,从1开始,最多可能需要查找8次。为什么呢?假设这个数字是8,从1开始,依次2,3,4,。。。,直至8,查找次数确实为8次。 采用二分方法,最多需要查找3次。为什么呢?仍然假设这个数字是8,将1~8从中间分开,假设第一次猜测为5,反 阅读全文
posted @ 2020-01-13 22:56 dogfaraway 阅读(272) 评论(0) 推荐(0) 编辑
摘要: 定义: 对于一种事物的本质特征或一个概念的内涵和外延所作的简要说明。相当于数学上的对未知数的设定赋值,比如“设某未知数为已知字母x以便于简化计算,”对某个命名的词汇赋与一定的意义或形象,则有利于交流中的识别及认同。 公理: 在数学中,公理这一词被用于两种相关但相异的意思之下——逻辑公理和非逻辑公理。 阅读全文
posted @ 2019-09-13 16:44 dogfaraway 阅读(4848) 评论(0) 推荐(0) 编辑
摘要: # 因子的使用 ------------------------------------------------------------------- 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) 编辑
摘要: # 数组 ##创建一个数组 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) 编辑
摘要: # 数据框 --------------------------------------------------------------------- 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) 编辑
摘要: 快速让你的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 阅读(820) 评论(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) 编辑