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

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.83333336 * as.numeric(as.character(5/6))
## [1] 55/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.lryc.cn/news/467585.html

相关文章:

  • MusePose模型部署指南
  • 又一次升级:字节在用大模型在做推荐啦!
  • 无线领夹麦克风怎么挑选,麦克风行业常见踩坑点,避雷不专业产品
  • OJ-1017中文分词模拟器
  • Unity 关于UGUI动静分离面试题详解
  • HarmonyNext保存Base64文件到Download下
  • 069_基于springboot的OA管理系统
  • hive数据库,表操作
  • openpnp - 在顶部相机/底部相机高级校正完成后,需要设置裁剪所有无效像素
  • Vue+TypeScript+SpringBoot的WebSocket基础教学
  • 大话网络协议:HTTPS协议和HTTP协议有何不同?为什么HTTPS更安全
  • 13图书归还-云图书管理系统(Vue3+Spring Boot+element plus)
  • 中航资本:“女人的茅台”重挫!超7700亿元英伟达概念业绩爆发
  • day7:软件包管理
  • 探索Konko AI:快速集成大语言模型的最佳实践
  • 网络地址和本地网络地址
  • 【closerAI ComfyUI】AI绘画界新技术RF Inversion图像编辑和风格迁移!能跟ipadapter争高低吗?
  • 【Spring篇】Spring的Aop详解
  • Spring与其他框架的比较
  • 论当前的云计算
  • Spring Boot 整合 RocketMQ 之消息消费手动提交 ACK 实战【案例分享】
  • 胃癌数据集(不定期更新)
  • zh/FAQ/CentOSStream-CentOS Stream 常见问题
  • 多台西门子PLC与多台三菱PLC之间实时通讯的方案(PLC内不用编程)
  • C++ [项目] 恶魔轮盘赌
  • 微信小程序版本更新管理——实现自动更新
  • Python使用Selenium库实现CSDN自动化发帖
  • StringBulider和StringBuffer的底层源码剖析
  • 手机空号过滤接口-在线手机空号检测-手机空号过滤API
  • ubuntu 用ss-TPROXY实现透明代理,基于TPROXY的透明TCP/UDP代理,在 Linux 2.6.28 后进入官方内核。