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/
相关推荐
2301_764441331 小时前
Python构建输入法应用
开发语言·python·算法
咨询QQ276998852 小时前
V-REP小车项目+匹配文档,基于V-REP与MATLAB联合仿真,小车能够完成循迹、避障、走...
开发语言
咩图2 小时前
C#创建AI项目
开发语言·人工智能·c#
豆沙沙包?2 小时前
2025年--Lc293-784. 字母大小写全排列(回溯)--java版
java·开发语言
珑墨2 小时前
【唯一随机数】如何用JavaScript的Set生成唯一的随机数?
开发语言·前端·javascript·ecmascript
周杰伦fans3 小时前
C# - Task 是什么?想象一下你在餐厅点餐
服务器·开发语言·c#
芳草萋萋鹦鹉洲哦3 小时前
【tauri+rust】App会加载白屏,有时显示在左上角显示一小块,如何优化
开发语言·后端·rust
前端世界3 小时前
float 还是 double?用储罐体积计算带你看懂 C 语言浮点数的真实世界坑
java·c语言·开发语言
豐儀麟阁贵3 小时前
8.5在方法中抛出异常
java·开发语言·前端·算法