当前位置:网站首页>2.2 basic grammar of R language
2.2 basic grammar of R language
2022-07-05 21:29:00 【A primary school student on the statistics Road】
2.2 R Basic grammar of language
2.2.1 data structure —— Vector structure
A vector is a one-dimensional simple array , Can store numeric , Character and logical data .
First, we use the most primitive and clumsy method to create a vector
function :c()
Using this function to create a vector is similar to SAS perhaps MATLAB Programming language , Both can be used. “=” To assign a value to a variable , Of course R It also has its own unique side , stay R In language , We can also use “<-” To assign a value to a variable , Give me a chestnut
For example, we want to give variable names a,b,c Assignment of three variables of , The assignment types are numerical , Character type and logical type , We can carry out the following operations :
It should be noted that :
- Character type input requires quotation marks
- Logical TRUE and FALSE Should be capitalized ( The point here is : I use it Rstudio Write the program , So in the input TRUE and FALSE If you lose in lowercase , The system will pop you up automatically Capitalize option to , Just press enter , Therefore, it is highly recommended that you download and use Rstudio It's really convenient !)
Finally, we can get the following results :
Now let's learn some more advanced functions
function :seq()
This function is used to create vector groups with a specified step size or a specified number ( If you do not set the step size and number by yourself, it defaults to 1), Examples are as follows :
Specify the step size :
Specified number :
We need to pay attention to : You must have a starting value to make the function run
function :rep()
The main purpose of this function is to duplicate elements , Because of different replication methods , We can specify different replication methods on the suffix in brackets , Because there are too many replication methods , So here we will only talk about the most basic usage and take an example of copying the element at the specified location for a specified number of times , If you need to ask Du Niang directly for the rest of the methods in practical application !
Examples of the most basic methods of use : The digital 1 Copy 6 All over :
An example of copying a specified location element for a specified number of times , Put the second element (2) And the fourth element (4) Copy 2 Time , Others are 1 Time :
Finally, let's talk about the splicing of vectors :
Functions that splice vectors by line :rbind()
Function of splicing vectors by column :cbind()
About the operation of vectors, you can search directly on the Internet , Many bloggers have summarized many tables of algorithms, which are very complete, and you can easily find them , I will not introduce more here , What I want to emphasize here is , When we use “+” When splicing two vectors with different lengths , The system will automatically splice the short vectors into a vector with the same length as the long vector from beginning to end, and then calculate , And this process can only be carried out when the length of the long vector is an integral multiple of the length of the short vector , Otherwise, the system will automatically report an error , for example :
All right. , That's it this time , Thank you for your support !!
边栏推荐
- vant 源码解析 之深层 合并对象 深拷贝
- AITM 2-0003 水平燃烧试验
- 阿里云有奖体验:用PolarDB-X搭建一个高可用系统
- MySQL deep paging optimization with tens of millions of data, and online failure is rejected!
- Teach yourself to train pytorch model to Caffe (I)
- 显示器要申请BS 476-7 怎么送样?跟显示屏一样吗??
- Parker driver maintenance COMPAX controller maintenance cpx0200h
- Selenium gets the verification code image in DOM
- 力扣------经营摩天轮的最大利润
- one hundred and twenty-three thousand four hundred and fifty-six
猜你喜欢
Opérations de lecture et d'écriture pour easyexcel
Access Zadig self-test environment outside the cluster based on ingress controller (best practice)
JMeter installation under win7
Incentive mechanism of Ethereum eth
R语言【数据管理】
Pytorch实战——MNIST数据集手写数字识别
Interviewer: will concurrent programming practice meet? (detailed explanation of thread control operation)
Golang(1)|从环境准备到快速上手
Using webassembly to operate excel on the browser side
Influence of oscilloscope probe on measurement bandwidth
随机推荐
浅聊我和一些编程语言的缘分
selenium 查找b或p标签的内容
场景化面试:关于分布式锁的十问十答
张丽俊:穿透不确定性要靠四个“不变”
Making global exception handling classes with aspect
vant 源码解析之 utils/index.ts 工具函数
Using webassembly to operate excel on the browser side
Dictionary tree simple introductory question (actually blue question?)
递归查询多级菜单数据
WPF gets the control in the datagridtemplatecolumn of the specified row and column in the DataGrid
Sequence alignment
显示器要申请BS 476-7 怎么送样?跟显示屏一样吗??
R语言【数据管理】
xlrd常见操作
"Grain mall" -- Summary and induction
Influence of oscilloscope probe on signal source impedance
Learning robots have no way to start? Let me show you the current hot research directions of robots
Opérations de lecture et d'écriture pour easyexcel
基于 Ingress Controller 在集群外访问 Zadig 自测环境(最佳实践)
Teach yourself to train pytorch model to Caffe (I)