R语言随笔
三只佩奇不结义
士人有百折不回之真心,方有万变不穷之妙用。
展开
-
R语言Codewars实战——Sum by Factors(4kyu)
Description:Given an array of positive or negative integersI= [i1,..,in]you have to produce a sorted array P of the form[ [p, sum of all ij of I for which p is a prime factor (p positive) of ij] ...]P will be sorted by increasing order of the prime nu原创 2020-08-19 14:03:08 · 391 阅读 · 0 评论 -
R语言Codewars实战——Best travel(5kyu)
Description:John and Mary want to travel between a few towns A, B, C … Mary has on a sheet of paper a list of distances between these towns. ls = [50, 55, 57, 58, 60]. John is tired of driving and he says to Mary that he doesn’t want to drive more than t原创 2020-08-18 22:57:01 · 809 阅读 · 0 评论 -
R语言Codewars实战——Exponentials as fractions(4kyu)
Description:The aim is to calculate exponential(x) (written exp(x)in most math libraries) as an irreducible fraction, the numerator of this fraction having a given number of digits.We call this function expand, it takes two parameters, x of which we want原创 2020-08-18 18:24:55 · 468 阅读 · 0 评论 -
R语言Codewars实战——Fibo akin(5kyu)
Description:Be u(n) a sequence beginning with:u[1] = 1, u[2] = 1, u[3] = 2, u[4] = 3, u[5] = 3, u[6] = 4,u[7] = 5, u[8] = 5, u[9] = 6, u[10] = 6, u[11] = 6, u[12] = 8,u[13] = 8, u[14] = 8, u[15] = 10, u[16] = 9, u[17] = 10, u[18]原创 2020-08-17 00:32:16 · 299 阅读 · 0 评论 -
R语言Codewars实战——Twice linear(4kyu)
Consider a sequence u where u is defined as follows:The number u(0) = 1 is the first one in u.For each x in u, then y = 2 * x + 1 and z = 3 * x + 1 must be in u too.There are no other numbers in u.Ex: u = [1, 3, 4, 7, 9, 10, 13, 15, 19, 21, 22, 27, …]原创 2020-08-16 22:34:34 · 287 阅读 · 0 评论 -
R语言Codewars实战——Number of trailing zeros of N!(5kyu)
Description:Write a program that will calculate the number of trailing zeros in a factorial of a given number.N! = 1 * 2 * 3 * … * NBe careful 1000! has 2568 digits…For more info, see: http://mathworld.wolfram.com/Factorial.htmlExampleszeros(6) = 1#原创 2020-08-16 11:34:30 · 274 阅读 · 0 评论 -
R语言Codewars实战——Rainfall
说明:这道题是真难到我了,主要是我不清楚怎么把字母之间的数字匹配出来,我初始的时候想的是正则表达式,但是R语言的正则表达式与我在python中学到的不同,且更加麻烦复杂,再者我又对正则表达式一知半解的,脑子真就慢慢变得迷糊了,直接看了别人的解法(整半天经验没变化,难受啊)。Description:data and data1 are two strings with rainfall records of a few cities for months from January to December.原创 2020-08-14 17:46:40 · 384 阅读 · 0 评论 -
R语言Codewars实战——Last digit of a large number(5kyu)
Description:Define a function that takes in two non-negative integers a and b and returns the last decimal digit of a^b. Note that a and b may be very large!For example, the last decimal digit of 9^7 is 9, since 9^7 = 4782969. The last decimal digit of (原创 2020-08-13 23:47:06 · 1261 阅读 · 0 评论 -
R语言Codewars实战——Help the bookseller !(6kyu)
Description:A bookseller has lots of books classified in 26 categories labeled A, B, ..., Z. Each book has a code c of 3, 4, 5 or more characters. The 1st character of a code is a capital letter which defines the book category.In the bookseller’s stockli原创 2020-08-13 11:03:24 · 270 阅读 · 0 评论 -
R语言实战——基于KNN聚类的时间序列分析预测
---title: "Summary of Reading"author: "ChenWei"date: "2020/6/24"output: word_document---```{r setup, include=FALSE}knitr::opts_chunk$set(echo = TRUE) 这一次我阅读的是Francisco Martinez等著的《Time Series Forecasting with KNN in R: the tsfknn Package》,这篇文章原创 2020-07-10 20:06:23 · 5283 阅读 · 0 评论 -
R语言实战——谱系聚类分析与动态聚类分析
一、理论二、实战分析x1 <- c(5,7,3,6,6)x2 <- c(7,1,2,5,6)X <- cbind(x1,x2)# 计算初始距离矩阵dist(X) # 默认计算欧式距离dist(X,diag=TRUE) # 显示对角线元素dist(X,diag=TRUE,upper = TRUE) # 显示对角线元素和上三角元素dist(X,method = 'manhattan')dist(X,method = 'minkowski',p=1)原创 2020-07-10 19:49:47 · 2047 阅读 · 0 评论 -
R语言实战——百分条图与雷达图
文章转载自“医学统计与R语言”公众号,文章链接为:文章链接百分条图输入1library(ggplot2)library(ggthemes)library(ggsci)library(rio)percentbar <- import("percentbar.xlsx")percentbar输出1 year government society Indivi...转载 2020-04-20 18:42:28 · 2422 阅读 · 0 评论 -
R语言实战——ROC曲线的绘制
前言:以前使用Matlab绘制ROC曲线常常是工具箱有就画,没有就不画,而且在想画的时候工具箱恰恰就没有,很纳闷。然后无意间发现了一篇用R语言绘制ROC曲线的文章,赶紧学了并分享出来,以备不时之需。先通过一个例子来讲解一下参数的作用,使用的数据是大名鼎鼎的Iris数据集,R语言自带。数据处理第一步当然得处理一下数据。默认的Iris数据集有三类鸢尾花,我目前的理解是只有二分类才画的出ROC曲...原创 2020-04-20 18:30:56 · 24459 阅读 · 1 评论 -
R语言学习——对整合和重构的理解
文章目录1 整合数据2 reshape2包2.1 融合2.2 重铸前言:R中提供了许多用来整合(aggregate)和重塑(reshape)数据的强大方法。在整合数据时,往往将多组观测替换为根据这些观测计算的描述性统计量。在重塑数据时,则会通过修改数据的结构(行和列)来决定数据的组织方式。本篇文章描述了用来完成这些任务的多种方式。1 整合数据在R中使用一个或多个by变量和一个预先定义好的...原创 2020-04-17 13:32:34 · 1050 阅读 · 1 评论 -
R语言实战——主成分分析理论推导与R语言实现
目录1 总体主成分1.1 主成分的定义与导出1.2 主成分的性质1.3 从相关矩阵出发求主成分2 样本主成分2.1 从S出发求主成分2.2 从R出发求主成分3 相关的R函数以及实例3.1 `princomp`函数3.2 `summary`函数3.3 `loadings`函数3.4 `predict`函数3.5 `screeplot`函数3.6 `biplot`函数4 实例附录——PCA高级散点图的...原创 2020-04-15 20:06:35 · 3817 阅读 · 2 评论 -
R语言实战——距离判别、贝叶斯判别、Fisher判别理论详细推导与R语言实现
前言判别分析是用以判别个体所属群体的一种统计方法,它产生于20世纪30年代,近年来,在许多现代自然科学的各个分支和技术部门中,得到广泛的应用.例如,利用计算机对一个人是否有心脏病进行诊断时,可以取一批没有心脏病的人,测其p个指标的数据,然后再取一批已知患有心胜病的人,同样也测得p个相同指标的数据,利用这些数据建一个判别函数,并求出相应的临界值,这时对于需要进行诊断的人,也同样测其p个指标的数据...原创 2020-04-06 22:05:14 · 24183 阅读 · 7 评论 -
R语言学习——一元与多元正态分布检验(也可以用于其他分布的检验)
生成随机数:# 生成随机数set.seed(1230) # 随机数种子y1 <- rnorm(100); # 标准正态分布N(0,1)y2 <- rexp(100,2); # 参数为2的指数分布Exp(2)y3 <- rt(100,1); # 自由度为1的t分布t(1)y4 <- -y2; # -Exp(2)1 图像法1.1 直方图...原创 2020-03-27 19:12:41 · 10389 阅读 · 0 评论 -
R语言学习——多元数据统计特征的分析(含马氏距离的计算及矩阵分解)
**前言:**将多元统计分析课程上学到的知识以编程的形式展现。本篇博客使用到的数据如下:"Wind" "Solar radiation" "CO" "NO" "NO2" "O3" "HC"8 98 7 2 12 8 27 107 4 3 9 5 37 103 4 3 5 6 310 88 5 2 8 15 46 91 4 2 8 10 38 90 5 2 12 12 49 8...原创 2020-03-18 18:14:22 · 5886 阅读 · 0 评论 -
R语言学习——最全R语言向量的生成与命名
首先需要说明的是,在R语言中向量和列表是不一样的,向量中每一个元素的类型都是一样的,而列表反之,这里的列表与Python中的列表有几分相似。以下是分类情况:同样类型的数据不同类型的数据一维向量(vector)列表(lists)R语言中生成常用向量主要有这么几个方法:方法1:...原创 2020-03-03 15:58:41 · 20919 阅读 · 1 评论