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语言 分类变量 虚拟变量