当前位置: 首页 > article >正文

R语言笔记(一)

文章目录

  • 一、R objects
  • 二、Types of data
  • 三、Operators
    • 1、Operators
    • 2、Comparison operators
    • 3、Logical operators
  • 四、Check types of data objects
  • 五、Convertion between data objects
  • 六、R workspace


一、R objects

Two basic types of things/objects: data and functions

  • Data: things like 6, “six”, 6.000 6.000 6.000, and [ 6 6 6 6 6 6 ] \left[ \begin{array}{ccc} 6 & 6 & 6 \\ 6 & 6 & 6\end{array}\right] [666666]
  • Functions: things like log, + (takes two arguments), < (two), sum (multiple), and mean (one)

二、Types of data

  • Booleans
  • Integers
  • Characters
  • Floating point numbers: an integer times a positive integer to the power of an integer, as in 3 × 1 0 6 3 \times 10^6 3×106 or 1 × 3 − 1 1 \times 3^{-1} 1×31
    • Double precision: 64 bits (8 bytes); Single precision: 32 bits (4 bytes)
  • Missing or ill-defined values: NA, NaN, etc.

三、Operators

1、Operators

  • Unary: take just one argument. E.g., - for arithmetic negation, ! for Boolean negation
  • Binary: take two arguments. E.g., +, -, *, and / (though this is only a partial operator). Also, %% (for mod), and ^ (again partial)
  • 一元运算符:只接受一个参数。例如,负号(-)用于算术取反,感叹号(!)用于布尔取反。
  • 二元运算符:接受两个参数。例如,加号(+)、减号(-)、乘号(*)和除号(/)(尽管除号只是部分运算符)。还有求余运算符(%%),以及幂运算(^)(同样是部分运算符)。
# %/% 执行整除运算,即只保留商的整数部分,舍弃余数。
# %% 是取模运算符,它返回除法后的余数。
# %/%%% 常配合使用来获取整数商和余数。

10 / 3   # 结果是 3.333333
10 %/% 3 # 结果是 3(商的整数部分)
10 %% 3  # 结果是 1(余数)

2、Comparison operators

These are also binary operators; they take two objects, and give back a Boolean.

6 > 5
6 < 5
6 >= 7

3、Logical operators

These basic ones are & (and) and | (or).

(5 > 7) & (6 * 7 == 42)
## [1] FALSE

(5 > 7) | (6 * 7 == 42)
## [1] TRUE

Note: The double forms && and || are different!


四、Check types of data objects

  • The typeof() function returns the data type
  • is.x() functions return Boolean values indicating whether the argument is of type x
typeof(6)
## [1] "double"
is.double(7)
## [1] TRUE
## 解释:在 R 语言中,数字的默认类型是 双精度浮点数(double)。

is.na(7)
## [1] FALSE
is.na(7/0)
## [1] FALSE
## 解释:跟数学里不同,7/0 = Inf  

is.na(0/0)
## [1] TRUE

五、Convertion between data objects

  • as.x() (tries to) “cast” its argument to type x, to translate it sensibly into such a value
as.character(5/6)
## [1] "0.833333333333333"

as.numeric(as.character(5/6))
## [1] 0.8333333

6 * as.numeric(as.character(5/6))
## [1] 5

5/6 == as.numeric(as.character(5/6))
## [1] FALSE

六、R workspace

Where do the variables live?

ls()
## [1] "approx.pi" "circumference" "diameter"

Getting rid of variables:

rm("circumference")
ls()
## [1] "approx.pi" "diameter"

rm(list=ls()) # Be warned! This erases everything
ls()
## character(0)

http://www.kler.cn/news/362966.html

相关文章:

  • HTML之表单设计
  • 无人机悬停精度算法!
  • Cilium + ebpf 系列文章- (七)Cilium-LoadBalancer类型的SVC的IPPool
  • 基于单片机的智能小区门禁系统设计(论文+源码)
  • mac m1 安装openresty以及redis限流使用
  • mysql学习教程,从入门到精通,sql序列使用(45)
  • 基于neo4j的糖尿病知识图谱数据
  • 深入浅出 Vue3 nextTick
  • 推荐一个开源非线性视频编辑器:Kdenlive
  • 在一台不能接入互联网的服务器(cenos7)安装DOCKER
  • 基于YOLOv8深度学习的无人机视角高精度太阳能电池板检测与分析系统【python源码+Pyqt5界面+数据集+训练代码】深度学习实战、目标分割
  • 成长的代价
  • Telephony Contact
  • 信息系统的分类
  • JavaScript进阶:手写代码挑战(一)
  • chat_gpt回答:python 复制xml文件
  • AI绘画教程分享:Stable Diffusion最新使用指南
  • 大括号块作用域的起源是什么?为什么整型数值用补码保存?char类型变量是存储为int类型大小吗?枚举为什么被当做整型?编程语言标识符为什么不能以数字开头?
  • Java最全面试题->Java基础面试题->JavaWeb面试题->Maven面试题
  • Cookie与Session详解与应用
  • LangGraph 源码分析 | 结构化输出
  • Umi UI报错:连接失败,请尝试重启dev服务
  • 从一个简单的计算问题,看国内几个大语言模型推理逻辑能力
  • 市面上什么台灯性价比高?五款超强实力护眼台灯测评推荐!
  • SVN小乌龟 create patch 和 apply patch 功能
  • 基于Multisim的水温控制电路设计与仿真