r語言 運算符_R語言運算符

r語言 運算符

R語言中的運算符 (Operators in R Language)

Generally speaking, an operator is a symbol that gives proper commands to the compiler regarding a specific action to be executed. The operators are used for carrying out the mathematical or logical calculations or also sometimes manipulations are also done using these operators. R language is normally considered as the rich language with several built-in operators to make a programmer more comfortable while coding the program. Moving further let us find what all are the inbuilt operators that are offered by the R language to its users.

一般來說,運算符是一個符號,它向編譯器提供有關要執行的特定操作的適當命令。 運算符用于執行數學或邏輯計算,或者有時也使用這些運算符進行操作。 R語言通常被認為是具有多種內置運算符的豐富語言,可以使程序員在編寫程序時更加舒適。 進一步講,我們可以找到R語言為其用戶提供的所有內置運算符。

Concerning other programming languages like C, C++, Java, etc, here also we find such similar operators that help the coders while coding their program. The commonly used operators are as follows:

關于其他編程語言(例如C,C ++,Java等),在這里我們也找到了類似的運算符,可在編碼程序時幫助編碼人員。 常用的運算符如下:

  1. Arithmetic operators

    算術運算符

  2. Relational Operators

    關系運算符

  3. Logical Operators

    邏輯運算符

  4. Assignment operators

    賦值運算符

  5. Miscellaneous operators

    雜項運營商

1)算術運算符 (1) Arithmetic Operators)

The operators like +, -, *, /, %%, %/%, ^ fall under the category of the arithmetic operators. The main usage of each operator is explained in details in the following text,

+,-,*,/,%%,%/%,^之類的運算符屬于算術運算符的類別。 下文詳細說明了每個運算符的主要用法,

Plus Operator (+): This operator helps in adding the two vectors.

加號運算符(+) :此運算符有助于將兩個向量相加。

Example:

例:

v <- c( 2,5.5,6)
t <- c(8, 3, 4)
print(v+t)

Output

輸出量

[1] 10.0  8.5 10.0

Minus Operator (-): This particular operator subtracts the second vector from the first one.

減號(-) :此特定運算符從第一個向量中減去第二個向量。

Example:

例:

v <- c( 2,5.5,6)
t <- c(8, 3, 4)
print(v-t)

Output

輸出量

[1] -6.0  2.5  2.0

Multiply Operator (*): It multiplies both vectors.

乘運算符(*) :將兩個向量相乘。

Example:

例:

v <- c( 2,5.5,6)
t <- c(8, 3, 4)
print(v*t)

Output

輸出量

[1] 16.0 16.5 24.0

Divide Operator (/): It mainly divides the first vector considered with the second one taken.

除法運算符(/) :主要將考慮的第一個向量除以第二個向量。

Example:

例:

v <- c( 2,5.5,6)
t <- c(8, 3, 4)
print(v/t)

Output

輸出量

[1] 0.250000 1.833333 1.500000

Remainder Operator (%%): It gives the remainder of the first vector that is considered with the second one.

余數運算符(%%) :它給出與第二個向量一起考慮的第一個向量的余數。

Example:

例:

v <- c( 2,5.5,6)
t <- c(8, 3, 4)
print(v%%t)

Output

輸出量

[1] 2.0 2.5 2.0

Division Operator (%/%): The result of the division of the first vector to the second one(quotient).

除法運算符(%/%) :第一個向量除以第二個向量(商)的結果。

Example:

例:

v <- c( 2,5.5,6)
t <- c(8, 3, 4)
print(v%/%t)

Output

輸出量

[1] 0 1 1

Raised to the Power (^): The first vector raised to the second one.

提高到冪(^) :第一個矢量提高到第二個。

Example:

例:

v <- c( 2,5.5,6)
t <- c(8, 3, 4)
print(v^t)

Output

輸出量

[1]  256.000  166.375 1296.000

2)關系運算符 (2) Relational Operators)

This is one of the sub-branches under the operators available in the R language. The main use of these operators is to find the relation between the two vectors considered.

這是R語言中可用的運算符的子分支之一。 這些運算符的主要用途是找到所考慮的兩個向量之間的關系。

The result of these operators is usually a boolean value.

這些運算符的結果通常是布爾值。

Coming to the list of available relational operators in the R language are as follows:

R語言中可用的關系運算符列表如下:

Greater Than>
Less Than<
Equal To==
Greater Than or Equal To>=
Less Than or Equal To<=
Not Equal To!=
比...更棒 >
少于 <
等于 ==
大于或等于 > =
小于或等于 <=
不等于 !=

The above operators have their own meanings while executing the program.

上述運算符在執行程序時具有各自的含義。

Greater Than Operator (>)

大于運算符(>)

The above operator helps the user in the process of determining whether the first number is greater than the second one.

上述運算符在確定第一數字是否大于第二數字的過程中幫助用戶。

Example:

例:

v <- c(2,5.5,6,9)
t <- c(8,2.5,14,9)
print(v>t)

Output

輸出量

[1] FALSE  TRUE FALSE FALSE

Less Than Operator (

少于運算符(

This operator tells the user whether the first operator is less than the second one.

該運算符告訴用戶第一個運算符是否小于第二個運算符。

Example:

例:

v <- c(2,5.5,6,9)
t <- c(8,2.5,14,9)
print(v < t)

Output

輸出量

[1]  TRUE FALSE  TRUE FALSE

Equal To Operator (==)

等于運算符(==)

Finds whether the both values are same to each other or not.

查找兩個值是否彼此相同。

Example:

例:

v <- c(2,5.5,6,9)
t <- c(8,2.5,14,9)
print(v == t)

Output

輸出量

[1] FALSE FALSE FALSE  TRUE

Greater Than or Equal To Operator (>=)

大于或等于運算符(> =)

Confirms whether each component of the foremost vector is superior than or equivalent to the corresponding part of the subsequent vector.

確認最前向量的每個分量是否優于或等效于后續向量的相應部分。

Example:

例:

v <- c(2,5.5,6,9)
t <- c(8,2.5,14,9)
print(v>=t)

Output

輸出量

[1] FALSE  TRUE FALSE  TRUE

Less Than or Equal To Operator (<=)

小于或等于運算符(<=)

Verifies if each component of the initial vector is less than or equal to the equivalent element of the next vector.

驗證初始向量的每個分量是否小于或等于下一個向量的等效元素。

Example:

例:

v <- c(2,5.5,6,9)
t <- c(8,2.5,14,9)
print(v<=t)

Output

輸出量

[1]  TRUE FALSE  TRUE  TRUE

Not Equal To Operator (!=)

不等于運算符(!=)

Verifies if each component of the initial vector is not equal to the equivalent element of the following vector.

驗證初始向量的每個分量是否不等于后續向量的等效元素。

Example:

例:

v <- c(2,5.5,6,9)
t <- c(8,2.5,14,9)
print(v!=t)

Output

輸出量

[1]  TRUE  TRUE  TRUE FALSE

3)邏輯運算符 (3) Logical Operators)

The following table shows all the available logical operators in the R language. The below operators are applicable over the vectors which are complex, logical or numeric-only. Here the R compiled assumes that all the numbers that are greater than the one are assumed to possess a logic value true.

下表顯示了R語言中所有可用的邏輯運算符。 以下運算符適用于復雜,僅邏輯或僅數字的向量。 在此,R編譯器假定所有大于一個的數字均具有邏輯值true。

Here while the logical operators are considered then every element available in the first vector is usually compared with the corresponding next element of the second vector. Thus, the result of the above comparison gives us a Boolean value.

在這里,在考慮邏輯運算符的同時,通常將第一向量中的每個可用元素與第二向量中的對應的下一個元素進行比較。 因此,以上比較的結果給出了一個布爾值。

The logical operators offered by the R language are as follows:

R語言提供的邏輯運算符如下:

Element-wise Logical AND operator&
Element-wise Logical OR operator|
Logical NOT operator!
Logical AND operator&&
Logical OR operator||
逐元素邏輯AND運算符
按元素邏輯或運算符 |
邏輯非運算符
邏輯AND運算子 &&
邏輯或運算符 ||

Element-wise Logical AND operator (&)

逐元素邏輯AND運算符(&)

It is named as the Element-wise Logical AND operator. It combines each component of the primary vector with the equivalent part of the next vector and gives an output TRUE if both the fundamental aspects are TRUE.

它被稱為Element-wise Logical AND運算符 。 如果兩個基本方面都為TRUE,它將主要向量的每個分量與下一個向量的等效部分合并,并給出輸出TRUE。

Example:

例:

v <- c(3,1,TRUE,2+3i)
t <- c(4,1,FALSE,2+3i)
print(v&t)

Output

輸出量

[1]  TRUE  TRUE FALSE  TRUE

Element-wise Logical OR operator (|)

逐元素邏輯或運算符(|)

It is termed as Element-wise Logical OR operator. It combines each element of the primary vector with the matching element of the subsequent vector and gives an output TRUE if one of the elements is TRUE.

它被稱為元素智能邏輯或運算符 。 它將主向量的每個元素與后續向量的匹配元素組合在一起,如果其中一個元素為TRUE,則輸出為TRUE。

Example:

例:

v <- c(3,0,TRUE,2+2i)
t <- c(4,0,FALSE,2+3i)
print(v|t)

Output

輸出量

[1]  TRUE FALSE  TRUE  TRUE

Logical NOT operator (!)

邏輯非運算符(!)

It is usually called with the name Logical NOT operator. The main function of this operator is that it takes each component of the vector and gives the contradictory logical value.

通常使用名稱Logical NOT運算符進行調用。 該運算符的主要功能是獲取矢量的每個分量并給出矛盾的邏輯值。

Example:

例:

v <- c(3,0,TRUE,2+2i)
print(!v)

Output

輸出量

[1] FALSE  TRUE FALSE FALSE

Logical AND operator (&&)

邏輯AND運算符(&&)

Named as Logical AND operator. It takes the initial component of the first vector and compares it with the second one and finally gives the TRUE value if and only if both are TRUE.

命名為邏輯AND運算符 。 它采用第一個向量的初始分量,并將其與第二個向量進行比較,并且當且僅當兩者均為TRUE時,才給出TRUE值。

Example:

例:

v <- c(3,0,TRUE,2+2i)
t <- c(1,3,TRUE,2+3i)
print(v&&t)

Output

輸出量

[1] TRUE

Logical OR operator (||)

邏輯或運算符(||)

It is termed as the Logical OR operator. The function of this operator is that it considers the primary components of both the vectors and eventually returns the value as TRUE if and only if one of them turns out to be TRUE.

它被稱為邏輯或運算符 。 該運算符的功能是,它考慮兩個向量的主要成分,并且僅當其中一個結果為TRUE時,才最終將值返回TRUE。

Example:

例:

v <- c(0,0,TRUE,2+2i)
t <- c(0,3,TRUE,2+3i)
print(v||t)

Output

輸出量

[1] FALSE

4)賦值運算符 (4) Assignment Operators)

The main intention of using these assignment operators in the program is to assign some value to the variables or vectors declared.

在程序中使用這些賦值運算符的主要目的是為聲明的變量或向量賦值。

There are two ways while assigning the vectors is considered in the R language. They are:

在R語言中,可以采用兩種方式分配向量。 他們是:

  • Right assignment

    正確的分配

  • Left assignment

    左分配

Right assignment:

正確分配:

The operators used for right assignment are as follows:

用于權限分配的運算符如下:

  • =

    =

  • <

    <

Example:

例:

v1 <- c(3,1,TRUE,2+3i)
v2 <<- c(3,1,TRUE,2+3i)
v3 = c(3,1,TRUE,2+3i)
print(v1)
print(v2)
print(v3)

Output

輸出量

[1] 3+0i 1+0i 1+0i 2+3i
[1] 3+0i 1+0i 1+0i 2+3i
[1] 3+0i 1+0i 1+0i 2+3i

Left assignment:

?

左分配:

Similarly, the operators used while implementing the left assignment technique is as follows:

同樣,實現左分配技術時使用的運算符如下:

  • ->

    ->

  • ->>

    ->>

Example:

例:

c(3,1,TRUE,2+3i) -> v1
c(3,1,TRUE,2+3i) ->> v2
print(v1)
print(v2)

Output

輸出量

[1] 3+0i 1+0i 1+0i 2+3i
[1] 3+0i 1+0i 1+0i 2+3i

5)雜項運營商 (5) Miscellaneous Operators)

These miscellaneous operators have their own specific purpose of usage in the program. They do not deal with either the logical or mathematical calculations or computations.

這些其他運算符在程序中有其特定的使用目的。 它們不處理邏輯或數學計算或計算。

OperatorDescriptionExample
:Colon operator: This operator creates the series of numerical in sequence for a considered vector.
v <- 2:8
print(v)

Output

%in%This operator is mainly used to recognize if an element/component belongs to the particular vector that is considered.
v1 <- 8
v2 <- 12
t <- 1:10
print(v1 %in% t)
print(v2 %in% t)

Output

%*%This particular operator is used in the case when the multiplication of a matrix with its transpose is required to be performed.
M = matrix( c(2,6,5,1,10,4), nrow = 2,ncol = 3,byrow = TRUE)
t = M %*% t(M)
print(t)

Output

操作員 描述
冒號運算符 :此運算符為考慮的向量順序創建一系列數值。
v < - 2 : 8
print ( v )

輸出量

%在% 該運算符主要用于識別元素/組件是否屬于所考慮的特定向量。
v1 < - 8
v2 < - 12
t < - 1 : 10
print ( v1 % in % t )
print ( v2 % in % t )

輸出量

%*% 在需要執行矩陣與其轉置相乘的情況下,使用此特定運算符。
M = matrix ( c ( 2 , 6 , 5 , 1 , 10 , 4 ) , nrow = 2 , ncol = 3 , byrow = TRUE )
t = M %*% t(M)
print(t)

輸出量

翻譯自: https://www.includehelp.com/r/operators.aspx

r語言 運算符

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/540529.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/540529.shtml
英文地址,請注明出處:http://en.pswp.cn/news/540529.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

[轉載] Python基礎之類型轉換與算術運算符

參考鏈接&#xff1a; Python中的運算符函數| 1 一、注釋 1.注釋&#xff1a;對程序進行標注和說明&#xff0c;增加程序的可讀性。程序運行的時候會自動忽略注釋。 2.單行注釋&#xff1a;使用#的形式。但是#的形式只能注釋一行&#xff0c;如果有多行&#xff0c;就不方便…

java awt 按鈕響應_Java AWT按鈕

java awt 按鈕響應The Button class is used to implement a GUI push button. It has a label and generates an event, whenever it is clicked. As mentioned in previous sections, it extends the Component class and implements the Accessible interface. Button類用于…

解決“由于應用程序的配置不正確,應用程序未能啟動,重新安裝應用程序可能會糾正這個問題”...

在VS2005下用C寫的程序&#xff0c;在一臺未安裝VS2005的系統上&#xff0c; 用命令行方式運行&#xff0c;提示&#xff1a; “系統無法執行指定的程序” 直接雙擊運行&#xff0c;提示&#xff1a; “由于應用程序的配置不正確&#xff0c;應用程序未能啟動&#xff0c;重新安…

qgis在地圖上畫導航線_在Laravel中的航線

qgis在地圖上畫導航線For further process we need to know something about it, 為了進一步處理&#xff0c;我們需要了解一些有關它的信息&#xff0c; The route is a core part in Laravel because it maps the controller for sending a request which is automatically …

Logistic回歸和SVM的異同

這個問題在最近面試的時候被問了幾次&#xff0c;讓談一下Logistic回歸&#xff08;以下簡稱LR&#xff09;和SVM的異同。由于之前沒有對比分析過&#xff0c;而且不知道從哪個角度去分析&#xff0c;一時語塞&#xff0c;只能不知為不知。 現在對這二者做一個對比分析&#xf…

[轉載] python學習筆記2--操作符,數據類型和內置功能

參考鏈接&#xff1a; Python中的Inplace運算符| 1(iadd()&#xff0c;isub()&#xff0c;iconcat()…) 什么是操作符&#xff1f; 簡單的回答可以使用表達式4 5等于9&#xff0c;在這里4和5被稱為操作數&#xff0c;被稱為操符。 Python語言支持操作者有以下幾種類型。 算…

scala bitset_Scala中的BitSet

scala bitsetScala BitSet (Scala BitSet) Set is a collection of unique elements. 集合是唯一元素的集合。 Bitset is a set of positive integers represented as a 64-bit word. 位集是一組表示為64位字的正整數。 Syntax: 句法&#xff1a; var bitset : Bitset Bits…

構建安全網絡 比格云全系云產品30天內5折購

一年之計在于春&#xff0c;每年的三、四月&#xff0c;都是個人創業最佳的起步階段&#xff0c;也是企業采購最火熱的時期。為了降低用戶的上云成本&#xff0c;讓大家能無門檻享受到優質高性能的云服務&#xff0c;比格云從3月16日起&#xff0c;將上線“充值30天內&#xff…

python中 numpy_Python中的Numpy

python中 numpyPython中的Numpy是什么&#xff1f; (What is Numpy in Python?) Numpy is an array processing package which provides high-performance multidimensional array object and utilities to work with arrays. It is a basic package for scientific computati…

[轉載] python之路《第二篇》Python基本數據類型

參考鏈接&#xff1a; Python中的Inplace運算符| 1(iadd()&#xff0c;isub()&#xff0c;iconcat()…) 運算符 1、算數運算&#xff1a; 2、比較運算&#xff1a; 3、賦值運算&#xff1a; 4、邏輯運算&#xff1a; 5、成員運算&#xff1a; 6、三元運算 三元運算&…

數據結構 基礎知識

一。邏輯結構: 是指數據對象中數據 素之間的相互關系。 其實這也是我 今后最需要關注的問題 邏輯結構分為以 四種1. 集合結構 2.線性結構 3.數形結構 4&#xff0c;圖形結構 二。物理結構&#xff1a; 1&#xff0c;順序存儲結,2 2. 鏈式存儲結構 一&#xff0c;時間復雜…

ruby 變量類中范圍_Ruby中的類

ruby 變量類中范圍Ruby類 (Ruby Classes) In the actual world, we have many objects which belong to the same category. For instance, I am working on my laptop and this laptop is one of those laptops which exist around the globe. So, this laptop is an object o…

以云計算的名義 駐云科技牽手阿里云

本文講的是以云計算的名義 駐云科技牽手阿里云一次三個公司的牽手 可能會改變無數企業的命運 2017年4月17日&#xff0c;對于很多人來說可能只是個平常的工作日&#xff0c;但是對于國內無數的企業來說卻可能是個會改變企業命運的日。駐云科技聯合國內云服務提供商阿里云及國外…

[轉載] python學習筆記

參考鏈接&#xff1a; Python | a b并不總是a a b 官網http://www.python.org/ 官網library http://docs.python.org/library/ PyPI https://pypi.python.org/pypi 中文手冊&#xff0c;適合快速入門 http://download.csdn.net/detail/xiarendeniao/4236870 py…

標志寄存器_訪問標志寄存器,并與寄存器B |交換標志寄存器F的內容 8085微處理器...

標志寄存器Problem statement: 問題陳述&#xff1a; Write an assembly language program in 8085 microprocessor to access Flag register and exchange the content of flag register F with register B. 在8085微處理器中編寫匯編語言程序以訪問標志寄存器&#xff0c;并…

瀏覽器端已支持 ES6 規范(包括 export import)

當然&#xff0c;是幾個比較優秀的瀏覽器&#xff0c;既然是優秀的瀏覽器&#xff0c;大家肯定知道是那幾款啦&#xff0c;我就不列舉了&#xff0c;我用的是 chrome。 對 script 聲明 type 為 module 后就可以享受 es6 規范所帶來的模塊快感了。 基礎語法既然是全支持&#xf…

[轉載] Python學習:Python成員運算符和身份運算符

參考鏈接&#xff1a; Python中和is運算符之間的區別 Python成員運算符 除了以上的一些運算符之外&#xff0c;Python還支持成員運算符&#xff0c;測試實例中包含了一系列的成員&#xff0c;包括字符串&#xff0c;列表或元組。 運算符 描述 實例 in 如果在指定的序列中找…

量詞邏輯量詞里面的v表示?_代理知識表示中的量詞簡介(基于人工智能)

量詞邏輯量詞里面的v表示&#xff1f;As we know that in an AI-based agent, the knowledge is represented through two types of logic: The propositional logic and the predicate logic. In the propositional logic, we have declarative sentences, and in the predica…

[轉載] Python 機器學習經典實例

參考鏈接&#xff1a; Python中的邏輯門 內容介紹 在如今這個處處以數據驅動的世界中&#xff0c;機器學習正變得越來越大眾化。它已經被廣泛地應用于不同領域&#xff0c;如搜索引擎、機器人、無人駕駛汽車等。本書首先通過實用的案例介紹機器學習的基礎知識&#xff0c;然后…

哈希表的最差復雜度是n2_給定數組A []和數字X,請檢查A []中是否有對X | 使用哈希O(n)時間復雜度| 套裝1...

哈希表的最差復雜度是n2Prerequisite: 先決條件&#xff1a; Hashing data structure 散列數據結構 Problem statement: 問題陳述&#xff1a; Given an array and a sum X, fins any pair which sums to X. Expected time complexity O(n). 給定一個數組和一個和X &#xff…