当前位置:网站首页>(1) Introduction Guide to R language - the first step of data analysis
(1) Introduction Guide to R language - the first step of data analysis
2022-07-06 12:20:00 【EricFrenzy】
notes : This blog aims to share personal learning experience , Please forgive me for any irregularities !
Catalog
R Language
Simply speaking ,R Language is a free open source 、 Powerful programming language for data analysis and visualization .R Please go to R Language website . Download the R After language , It is recommended to download, install and use RStudio This development environment .
When the download is complete , open RStudio, You will see the interface shown in the figure below :
On the left is Console, You can directly enter the order . If you want to create files and write code , Click the pull-down menu in the top left corner to select . It's commonly used R Script file .
Next, the operation of bloggers can be all in Console in .
Numeric and logical operators
use R It's easy to calculate , Just in Console Type the order in and then enter .
Common numerical operators are shown in the following table :
Symbol | meaning | give an example |
---|---|---|
+ | Addition operation | 5+3 Output is 8 |
- | Subtraction | 7-4 Output is 3 |
* | Multiplication | 2*5 Output is 10 |
/ | Starting operation | 10/4 Output is 2.5 |
^ | Index of operation | 2^5 Output is 32 |
%% | model / Take over operations | 5%%2 Output is 1 |
%/% | Division operation | 11%/%3 Output is 3 |
The logical operators commonly used in the following tables :
Symbol | meaning | explain | give an example |
---|---|---|---|
== | be equal to | If the symbols are equal twice , Return to true | 4==3 Output is F |
>= | Greater than or equal to | If the front of the symbol is greater than or equal to the back of the symbol , Return to true | 4>=3 Output is T |
<= | Less than or equal to | If the front of the symbol is less than or equal to the back of the symbol , Return to true | 4<=3 Output is F |
!= | It's not equal to | If the symbols are not equal twice , Return to true | 4!=3 Output is T |
> | Greater than | If the front of the symbol is greater than the back of the symbol , Return to true | 4>3 Output is T |
< | Less than | If the front of the symbol is less than the back of the symbol , Return to true | 4<3 Output is F |
&& | Logic and | If the symbol is true before and after , Return to true | (4==4)&&(3==2) Output is F |
|| | Logic or | If at least one before or after the symbol is true , Return to true | (4>3)||(4>6) Output is T |
Variable type and assignment
R Language variables are generally created without declaring types . In Computational Biology , The following five types of data are the most common :
type | explain | give an example |
---|---|---|
character | character string | “abc” |
numeric | Floating point numbers Inf Express R The upper limit of NaN Representational image 0/0 Undefined value of | 1.02 |
integer | integer When assigning values, add L, No, the default is numeric | 15L |
complex | The plural | 1+2i |
logical | Logical value or Boolean value Case sensitive | T or TRUE F or FALSE |
The following commands are used to create variables and assign values to variables / Update value :
x <- 4
x <- x + 1
After this order is executed , stay Console hit x enter , Will return the current variable x Value (5). stay RStudio On the right side of the Environment I will go out x And its value (5). If you want to know all variables , Please be there. Console Use the following command :
rm(list= ls())
Complex data structure , Such as vector and data.frame, It will be explained in the subsequent use .
Logical decision and cycle
R Linguistic if else、for、while Grammar and C The language is similar , See the following example for details :
#if(){}else{}
# If the condition in brackets is true , Then execute the code in curly brackets and end , Otherwise, skip the code in curly brackets
# Can be in a if Nested in another if, Used to make more complex condition judgments
# there print() Function can output the contents in parentheses
# Try at Console Li Da ?print() or ? Add any function you are not sure about and enter , Instructions will appear on the lower right
x <- 20
y <- 30
if(x<y && y-x>15){
print("Condition 1")
} else {
print("Condition 2")
}
# The output should be "Condition2"
#for(){}
# Determine the number of times the code in curly braces is repeatedly executed according to the range in brackets
# For example, the following code i in 1:5, You mean for i=1,2,3,4,5
# That is to say, the code will be executed five times
# Again , Can be in a for loop Nested in another for loop
for(i in 1:5){
print(i^2)
}
# The output should be 1 4 9 16 25
#while(){}
# Loop through the code in curly braces , Until the condition of parentheses is false
# it is to be noted that , The condition in brackets is always true, and many words will loop
x <- 1
while(x < 10){
print(x)
x <- x + 1
}
# The output should be 1 2 3 4 5 6 7 8 9
Conclusion
R That's all for language introduction . I'll explain it in detail next time vector、matrix、list These data structures , Coming soon ! If you have any questions or suggestions, please leave messages and comments !
边栏推荐
- Symbolic representation of functions in deep learning papers
- ARM PC=PC+8 最便于理解的阐述
- gcc 编译选项
- (四)R语言的数据可视化——矩阵图、柱状图、饼图、散点图与线性回归、带状图
- ESP学习问题记录
- Kaggle competition two Sigma connect: rental listing inquiries
- Intermediate use tutorial of postman [environment variables, test scripts, assertions, interface documents, etc.]
- ESP8266通过arduino IED连接巴法云(TCP创客云)
- Esp8266 uses Arduino to connect Alibaba cloud Internet of things
- .elf .map .list .hex文件
猜你喜欢
ES6语法总结--上篇(基础篇)
MP3mini播放模块arduino<DFRobotDFPlayerMini.h>函数详解
Unit test - unittest framework
MySQL时间、时区、自动填充0的问题
Mp3mini playback module Arduino < dfrobotdfplayermini H> function explanation
(三)R语言的生物信息学入门——Function, data.frame, 简单DNA读取与分析
MySQL占用内存过大解决方案
基于Redis的分布式ID生成器
数据库课程设计:高校教务管理系统(含代码)
Redis 缓存更新策略,缓存穿透、雪崩、击穿问题
随机推荐
.elf .map .list .hex文件
Common properties of location
@The difference between Autowired and @resource
ESP learning problem record
Cannot change version of project facet Dynamic Web Module to 2.3.
Basic operations of databases and tables ----- creating data tables
ES6语法总结--上篇(基础篇)
Redis 缓存更新策略,缓存穿透、雪崩、击穿问题
History object
open-mmlab labelImg mmdetection
JS数组常用方法的分类、理解和运用
(三)R语言的生物信息学入门——Function, data.frame, 简单DNA读取与分析
Detailed explanation of truncate usage
Basic operations of databases and tables ----- view data tables
Redis based distributed ID generator
(四)R语言的数据可视化——矩阵图、柱状图、饼图、散点图与线性回归、带状图
About using @controller in gateway
Whistle+switchyomega configure web proxy
Pytoch implements simple linear regression demo
OSPF message details - LSA overview