R语言06-R语言的基本运算

概念

R语言支持多种基本运算,包括算术运算、逻辑运算、比较运算和向量化运算等。

代码示意

逻辑运算

python 复制代码
a <- TRUE
b <- FALSE

logical_and <- a & b  # 逻辑与
logical_or <- a | b   # 逻辑或
logical_not <- !a     # 逻辑非

比较运算

python 复制代码
x <- 5
y <- 3

equal <- x == y       # 相等
not_equal <- x != y   # 不相等
greater_than <- x > y # 大于
less_than <- x < y    # 小于
greater_equal <- x >= y  # 大于等于
less_equal <- x <= y     # 小于等于

向量化运算

python 复制代码
vector1 <- c(1, 2, 3, 4, 5)
vector2 <- c(2, 3, 4, 5, 6)

vector_sum <- vector1 + vector2   # 向量加法
vector_product <- vector1 * vector2  # 向量乘法
vector_mean <- mean(vector1)  # 计算向量的平均值
相关推荐
码途行者7 小时前
每天10分钟学Go:第17课 接口interface-只规定“能做什么“,不管它是什么
开发语言·后端·golang
头发还在的女程序员8 小时前
Java充电桩平台源码解析:枪口状态、上报时间与页面刷新怎样协同
java·开发语言·充电桩系统·充电桩管理·充电系统·充电小程序
timeDifference₇9 小时前
Python Vibe Coding实操实验报告
开发语言·jvm·python
geovindu10 小时前
python:DecisionTree
开发语言·后端·python·算法
geovindu11 小时前
python: Decision Tree Regressor
开发语言·后端·python·算法·决策树
炸膛坦客15 小时前
单片机/C/C++八股:(三十七)指针数组 和 数组指针
c语言·开发语言·c++
夜不会漫长15 小时前
C++:C++11特性
开发语言·c++·算法
apcipot_rain16 小时前
C++转java日记(13)
java·开发语言
郝学胜-神的一滴17 小时前
Effective Python 条款41:试Mix‑In组合式开发
开发语言·pytorch·python·pycharm·numpy
吃我一窝jio17 小时前
Python与Redis集合深度解析
开发语言·redis·笔记·python