当前位置:网站首页>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 !!
边栏推荐
- Parker driver maintenance COMPAX controller maintenance cpx0200h
- Simple interest mode - lazy type
- MySQL ifnull usage function
- Zhang Lijun: penetrating uncertainty depends on four "invariants"
- 【日常训练--腾讯精选50】89. 格雷编码(看题解才会的)
- Deep merge object deep copy of vant source code parsing
- Xlrd common operations
- Traps in the explode function in PHP
- 秋招将临 如何准备算法面试、回答算法面试题
- Golang (1) | from environmental preparation to quick start
猜你喜欢

第05章_存储引擎

Display DIN 4102-1 Class B1 fire test requirements

事项研发工作流全面优化|Erda 2.2 版本如“七”而至

Chapter 05_ Storage engine

Reading and writing operations of easyexcel

ArcGIS栅格重采样方法介绍

MySQL deep paging optimization with tens of millions of data, and online failure is rejected!

Deployment of Jenkins under win7

Enclosed please find. Net Maui's latest learning resources

leetcode:1139. The largest square bounded by 1
随机推荐
Chapter 05_ Storage engine
Test of incombustibility of cement adhesives BS 476-4
2022-07-03-cka- latest feedback from fans
MySQL InnoDB Architecture Principle
AITM2-0002 12s或60s垂直燃烧试验
Reading and writing operations of easyexcel
LeetCode: Distinct Subsequences [115]
Arcgis\qgis no plug-in loading (no offset) mapbox HD image map
vant 源码解析之 utils/index.ts 工具函数
Two ways to realize video recording based on avfoundation
终端安全能力验证环境搭建和渗透测试记录
显示屏DIN 4102-1 Class B1防火测试要求
Influence of oscilloscope probe on measurement bandwidth
显示器要申请BS 476-7 怎么送样?跟显示屏一样吗??
Display DIN 4102-1 Class B1 fire test requirements
木板ISO 5660-1 热量释放速率摸底测试
sql常用语法记录
Deep merge object deep copy of vant source code parsing
MMAP
思特奇加入openGauss开源社区,共同推动数据库产业生态发展