android r中的变量_R中的变量

android r中的变量

Variables in R are the same as the notion of variables in any other programming language. Variable is a name we assign for the storage space location that stores our data. A variable in R can be of any datatype, simple or complex. There are certain rules and conventions when working with variables in R.

R中的变量与任何其他编程语言中的变量概念相同。 变量是我们为存储数据的存储空间位置分配的名称。 R中的变量可以是任何数据类型,简单或复杂。 在R中使用变量时,有某些规则和约定。

R中的变量–命名规则 (Variables in R – Naming Rules)

The name of a variable is known as an identifier. Not every string can be an identifier in R.

变量的名称称为标识符。 并非每个字符串都可以是R中的标识符。

  • Variables in R are case sensitive. The names Car, car and CAR are all treated as different variables in spite of the same spelling.

    R中的变量区分大小写 。 尽管拼写相同,但名称CarcarCAR都被视为不同的变量。

  • Variables can never begin with symbols or numbers. 1car and &car are not valid variable names.

    变量永远不能以符号或数字开头1car&car不是有效的变量名称。

  • Variable names can begin with a period (.). However, if a name starts with a period, it must be followed by a letter instead of a number.

    变量名可以以句点.开头 。 但是,如果名称以句点开头,则必须在其后加上字母而不是数字。

  • For defining complex names, period or underscore can be used as the seperator. For example, a.one and a_one are both valid variable names.

    为了定义复杂的名称,可以使用句点或下划线作为分隔符。 例如, a.onea_one都是有效的变量名。

  • However, since underscore was used as an assignment operator in earlier versions of R, a period is preferred over underscore.

    但是,由于下划线在R的早期版本中用作赋值运算符,因此, 下划线优先于下划线

  • Variable names can never contain a blank space.

    变量名绝不能包含空格

变量分配 (Variable Assignment)

In the previous post on data types in R, we have introduced the assignment operator in R <-. This is knows as the gets operator. When we write a statement a <- b, it can be verbally expressed as, a gets the value of b.

在上一篇有关R中的数据类型的文章中 ,我们在R <-引入了赋值运算符。 这就是gets运算符。 当我们编写语句a <- b ,可以将其口头表达为a获得b的值

Never put a space between the less than and hyphen in our gets operator. The statement a <- 10 is an assignment statement, whereas a < -10 is interpreted as a less than minus 10, resulting in a Boolean output.

切勿在我们的gets运算符中的小于和连字符之间放置空格。 语句a <- 10是赋值语句,而a < -10被解释为小于负10,从而导致布尔输出。

In addition to the gets operator, there is also the right assignment operator, that is a reverse of gets ->. The statement 10 -> a is equivalent to a <- 10.

除了gets运算符外,还有一个正确的赋值运算符,它与gets- ->的相反。 语句10 -> a等效于a <- 10

Also, the equals sign can be used for assignment of variables in R just like C or C++. The statement a = b is a valid one.

同样, 等号可以像C或C ++一样用于R中的变量赋值。 语句a = b是有效的语句。

一些有用的变量提示 (Some Useful Tips with Variables)

  • When working with complex projects, it sometimes gets tedious to remember all the variable names. Therefore you can type in ls() in the console to get a list of all active variables.

    在处理复杂项目时,记住所有变量名有时会很麻烦。 因此,您可以在控制台中键入ls()以获取所有活动变量的列表。
  • To remove a specific variable from the environment the command is rm(<variablename>). The space gets freed and can be reassigned to another variable now. To remove a variable named x, simply type in rm(x).

    要从环境中删除特定变量,命令为rm(<variablename>) 。 该空间已释放,现在可以将其重新分配给另一个变量。 要删除名为x的变量,只需键入rm(x)
  • The code snippet below displays the ls() utility. All the variables and function names in the enivornment get displayed.

    下面的代码片段显示了ls()实用程序。 显示环境中的所有变量和函数名称。

> ls()
 [1] "a"          "a_one"      "average"    "b"          "c"          "code"      
 [7] "division"   "elfunction" "fs"         "myname"     "myname2"    "myvector"  
[13] "name
  • Suppose that we need to remove a variable named average, it can be done by typing in rm(average) . Using ls again, we see that the variable in no longer in the environment.

    假设我们需要删除一个名为average的变量,可以通过输入rm(average)来完成。 再次使用ls ,我们看到该变量不再存在于环境中。

> rm(average)
> ls()
 [1] "a"          "a_one"      "b"          "c"          "code"       "division"  
 [7] "elfunction" "fs"         "myname"     "myname2"    "myvector"   "name" 

翻译自: https://www.journaldev.com/34455/variables-in-r

android r中的变量

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值