R语言笔记(一)

news/2024/10/24 9:51:31/

文章目录

  • 一、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.ppmy.cn/news/1541567.html

相关文章

定时任务使用kafka

定时任务使用kafka 在上述业务场景中使用 Kafka 而不是直接定时执行任务有以下几个重要原因&#xff1a; 一、解耦 任务触发与执行分离&#xff1a; 使用 XXL-JOB 定时触发任务并将任务消息发送到 Kafka&#xff0c;实现了任务触发端&#xff08;通常是调度系统&#xff09;和…

element 中 el-dialog 在不同的文件中使用

在实际中工作&#xff0c;我们经常需要使用 el-dialog 来做一个弹框的功能。最常见的就是在父组件中点击一个按纽&#xff0c;然后弹出一个框。而这个框就是子组件。同时&#xff0c;父子组件是分布在不同的文件中。 <!--父组件--> <template> <div> <…

LabVIEW继电器视觉检测系统

随着制造业的自动化与高精度要求不断提升&#xff0c;传统的人工检测方法逐渐难以满足高效和高精度的需求。特别是在航空航天、医疗设备等高端领域&#xff0c;密封继电器推动杆部件的质量直接影响到设备的性能与可靠性。LabVIEW自动化视觉检测系统&#xff0c;能对推动杆部件进…

TCP(三次握手)和UDP(面向无连接)的原理以及区别

TCP(三次握手)和UDP&#xff08;面向无连接&#xff09;的原理以及区别 网络协议是每个前端工程师都必须要掌握的知识&#xff0c;TCP/IP 中有两个具有代表性的传输层协议。 概述 &#x1f4e1;TCP&#xff08;Transmission Control Protocol&#xff09;是一种网络协议&#…

计算机视觉中的坐标变换

1.概述 高级驾驶辅助系统&#xff08;ADAS&#xff09;领域&#xff0c;存在多种常用的坐标系&#xff1a;LiDAR 坐标系、车辆坐标系、相机坐标系、图像坐标系等。因为和这些坐标系频繁打交道&#xff0c;本文对点的旋转与坐标系旋转等变换给出直观推导与说明。 2.坐标点平移…

C++进阶——红黑树

目录 一、概念 二、特征 三、模拟实现 1.大致框架 2.插入分析 3.插入代码 四、测试 一、概念 红黑树是一颗近似平衡的二叉搜索树&#xff0c;最长路径的长度不会超过最短路径的两倍&#xff0c;主要是通过控制结点的“颜色”来实现的&#xff0c;第一次接触红黑树可能会…

MySQL【知识改变命运】复习前1~11

复习 1&#xff1a;客户端和数据库操作2&#xff1a;表操作3: CRUD 增删改查4:数据库约束5:表的设计6:聚合函数7:GROUP BY分组查询和HAVING子句8:联合查询(表连接查询) 1&#xff1a;客户端和数据库操作 1. 登录 mysql -uroot -p > 2. 查看当前数据库的版本 select version(…

RabbitMQ概述

Rabbit是一个公司名.MQ也就是消息队列的意思&#xff0c;RabbitMQ是Rabbit企业下一个消息队列产品。 RabbitMQ是一个实现了AMQP的消息队列服务&#xff0c;是当前主流的消息中间件。 什么是MQ MQ&#xff08;message queue&#xff09;&#xff0c;本身是个队列&#xff0c;…