r語言 分類變量 虛擬變量
R語言| 變數 (R Language | Variables)
In the previous tutorial, we have come across the basic information that stands as a pavement for understanding the R language in depth. Now moving future let us educate ourselves about the concept of Variables that are used in the R language.
在上一教程中,我們了解了一些基本信息,它們是深入理解R語言的基礎。 現在,展望未來,讓我們對R語言中使用的變量的概念進行自我教育。
Variables are the storage places in the R language: They stay responsible for creating a memory for storing the data after they are created. The variables are so powerful that if they are changed then the result of the program will change. That means the variables are the components in the R language in which they have the capability of manipulating the program whatever we have written.
變量是R語言的存儲位置 : 變量創建后,仍負責創建用于存儲數據的內存。 變量是如此強大,以至于如果改變了它們,那么程序的結果將會改變。 這意味著變量是R語言中的組成部分,它們具有操縱我們所編寫程序的能力。
變量中存儲了什么? (What are stored in a variable?)
Every one of us is acquainted with the fact that the variables in the other programming languages also work on the same principle as that in the R language. In simple terms, we can confess that the variables act like the containers that store the data which is given by the user.
我們每個人都熟悉這樣的事實,即其他編程語言中的變量也按照與R語言相同的原理工作。 簡單來說,我們可以承認變量的作用類似于存儲用戶提供的數據的容器。
The variables in the R language are capable enough to store the atomic vector or a group of atomic vectors in them. In addition to that, they can also reserve R objects.
R語言中的變量足以存儲原子向量或一組原子向量。 除此之外,它們還可以保留R對象。
Syntax followed to declare a variable in the r language:
遵循語法以r語言聲明變量:
A variable name that exists to be valid should consist of numbers, letters, or dots. In addition to that one can also use the underline characters while giving a name to the variable.
存在的有效變量名應該由數字,字母或點組成。 除此以外,還可以在給變量命名的同時使用下劃線字符。
But there is a strict rule in the R language which speaks about the concept I how to give a perfect name to the variable as per the conventions provided by the seniors. Whatever the name the user assigns for the variable but the name of the variable must start with a letter which should not be followed by a number. Also one can give a name with a dot at first followed by other letters.
但是R語言中有一個嚴格的規則,該規則涉及有關如何按照老年人提供的約定為變量賦予完美名稱的概念。 用戶為變量分配的名稱是什么,但變量的名稱必須以字母開頭,字母后不能跟數字。 也可以先給一個名字加一個點,然后再加上其他字母。
Examples:
例子:
var_name2 : valid
var_name% : invalid
2var_name : invalid
_variable_name: invalid
變量分配 (Variable Assignment)
The general convention followed for assigning the values to the variables is by making the use of rightward, leftward, or the equal to operator. Furthermore, the value stored in ten variables can be displayed over the screen with the help of the below functions:
將值分配給變量的通用約定是使用向右,向左或等于運算符。 此外,借助以下功能,可以將十個變量中存儲的值顯示在屏幕上:
print()
打印()
cat()
貓()
The cat() function in the R language plays an important role in the process of combining various items as a part of the same or continuous output in the printing phase.
R語言中的cat()函數在將各種項目組合為打印階段中相同或連續輸出的一部分的過程中起著重要作用。
# Assignment using equal operator.
var.1 = c(0,1,2,3)
# Assignment using leftward operator.
var.2 <- c("learn","R")
# Assignment using rightward operator.
c(TRUE,1) -> var.3
print(var.1)
cat ("var.1 is ", var.1 ,"\n")
cat ("var.2 is ", var.2 ,"\n")
cat ("var.3 is ", var.3 ,"\n")
The above is the code that represents the concept of assigning the variable in the R language.
上面的代碼代表了用R語言分配變量的概念。
Output
輸出量
[1] 0 1 2 3
var.1 is 0 1 2 3
var.2 is learn R
var.3 is 1 1
翻譯自: https://www.includehelp.com/r/variables-in-the-r-language.aspx
r語言 分類變量 虛擬變量