官术网_书友最值得收藏!

Core essentials of R programming

One of the reasons for R's success is its use of variables. Variables are used in all aspects of R programming. For example, variables can hold data, strings to access a database, whole models, queries, and test results. Variables are a key part of the modeling process, and their selection has a fundamental impact on the usefulness of the models. Therefore, variables are an important place to start since they are at the heart of R programming.

Variables

In the following section we will deal with the variables—how to create variables and working with variables.

Creating variables

It is very simple to create variables in R, and to save values in them. To create a variable, you simply need to give the variable a name, and assign a value to it.

In many other languages, such as SQL, it's necessary to specify the type of value that the variable will hold. So, for example, if the variable is designed to hold an integer or a string, then this is specified at the point at which the variable is created.

Unlike other programming languages, such as SQL, R does not require that you specify the type of the variable before it is created. Instead, R works out the type for itself, by looking at the data that is assigned to the variable.

In R, we assign variables using an assignment variable, which is a less than sign (<) followed by a hyphen (-). Put together, the assignment variable looks like so:

Working with variables

It is important to understand what is contained in the variables. It is easy to check the content of the variables using the ls command. If you need more details of the variables, then the ls.str command will provide you with more information.

If you need to remove variables, then you can use the rm function.

主站蜘蛛池模板: 安远县| 邯郸县| 新邵县| 沙洋县| 定南县| 孟连| 富平县| 周口市| 潞城市| 麻江县| 肥城市| 民和| 资中县| 正蓝旗| 云阳县| 疏附县| 南汇区| 齐河县| 揭西县| 琼中| 长岛县| 思南县| 营口市| 日照市| 乐安县| 广丰县| 新郑市| 石台县| 湖口县| 长泰县| 商水县| 西林县| 海阳市| 南川市| 平原县| 望都县| 西藏| 北碚区| 乌兰察布市| 肥东县| 赞皇县|