R notes[2]

文章目录

sequence

  1. organized equence is a regular facility of R language,it can be generated by the seq() function.of couse ,in oder to make arbitrary list, the c() is used to achieve the task,that is explained at the previous note.
    the seq funtcion forms as follows.
r 复制代码
seq(from_value,to_value,step)
r 复制代码
> seq(1,10,2)
[1] 1 3 5 7 9
> seq(1,10,1)
 [1]  1  2  3  4  5  6  7  8  9 10
> seq(1,10,7)
[1] 1 8
> seq(10,1,-1)
 [1] 10  9  8  7  6  5  4  3  2  1

you may assign arguments in keyword,for example, seq(to=1,from=10,by=-1).

the rep function also make sequence which is different from seq,rep puts the same elements together into a list with specified number of times by default.

r 复制代码
> rep(-1,3)
[1] -1 -1 -1
r 复制代码
> rep(1,each=2)
[1] 1 1
> rep(1,times=2)
[1] 1 1
> rep(1,2)
[1] 1 1

We need to pay attention that if given element is a list,the rep have a argument named each which will repeatedly generate each element of given list for specified number of times and then arrange them in original order of each element .

r 复制代码
> a<-c(1,2)
> rep(a,3)
[1] 1 2 1 2 1 2
> rep(a,times=3)
[1] 1 2 1 2 1 2
> rep(a,each=3)
[1] 1 1 1 2 2 2

references

  1. https://cran.r-project.org/doc/manuals/
相关推荐
2601_962071578 小时前
【Java报错已解决】org.springframework.beans.factory.BeanCreationException
java·开发语言
淡海水9 小时前
07-04-并发-ConcurrentBag-T-工作窃取WorkStealing算法
开发语言·算法·c#·bag·concurrent·workstealing
CS_Zero10 小时前
C语言sizeof是函数吗?
c语言·开发语言
-今昭-11 小时前
《V2V 迁移实战:将 VMware 虚拟机转为 OpenStack 可用 Glance qcow2 镜像》
开发语言·python
黑马程序员毕设12 小时前
基于Java的医院药品管理系统的优化设计与实现
java·开发语言·spring boot·小程序·架构·课程设计·毕设
statistican_ABin13 小时前
全球教育水平提升预测分析报告——基于R语言随机森林回归模型的全球40国1960-2020年教育水平预测研究
随机森林·回归·r语言
_Twink1e13 小时前
openJiuwen 实训营 Day 1 · WorkSwarm 入门教程
开发语言·c++·openjiuwen
问天_观心13 小时前
大模型微调学习(一)
开发语言·人工智能·学习·语言模型·github
阿里嘎多学长13 小时前
2026-09-03 GitHub 热点项目精选
开发语言·程序员·github·代码托管
源代码•宸14 小时前
前置准备:定时微服务背景和现状
开发语言·经验分享·后端·微服务·云原生·架构·golang