r语言是高级编程语言_R编程语言中的数据类型

r语言是高级编程语言

Generally, while doing programming in any programming language, you need to use different variables to store information. Variables are nothing but some reserved memory locations to store the values. This means that you reserve some space in memory when you create a variable.

通常,在以任何一种编程语言进行编程时,您需要使用不同的变量来存储信息。 变量不过是一些保留值的存储位置。 这意味着您在创建变量时会在内存中保留一些空间。

Contrary to other programming languages like C, C++, and Java in R, the variables are not declared as some data type. The variables in R are R-Objects and the data type of the R-object becomes the data type of the variable. There are different types of R-objects. The frequently used ones are:

与R中的其他编程语言(例如C,C ++和Java)相反,变量未声明为某些数据类型 。 R中的变量是R对象,R对象的数据类型变为变量的数据类型。 有不同类型的R对象。 常用的是:

  1. Vectors

    向量

  2. Lists

    清单

  3. Matrices

    矩阵

  4. Arrays

    数组

  5. Factors

    因素

  6. Data Frames

    数据框

1)向量 (1) Vectors)

When vector is created with more than one element, you should use c() function which means to combine the elements into a vector.

当使用多个元素创建矢量时,应使用c()函数,这意味着将这些元素组合成一个矢量。

# Create a vector.
apple 

The above code, it produces the following result

2) Lists

A list is another R-object which can contain many different types of elements inside it like functions, vectors and even another list inside it.

# Create a list.
list1 

When we execute the above code, it produces the following result

3) Matrices

A matrix is a 2D rectangular data set. It can be created using a vector input which can be given to the matrix function.

# Create a matrix.
M = matrix( c('a','a','b','c','b','a'), nrow = 2, ncol = 3, byrow = TRUE)
print(M)

When we execute the code, it produces the following result

4) Arrays

While matrices are just upto two dimensions, arrays can be of any dimension. The array function takes a dim (dimension) attribute which creates the required number of dimension. In the example below we create an array with two elements which are 3x3 matrices each.

# Create an array.
a 

When we execute the above code, it produces the following result

5) Factors

Factors are other R-objects which are created using a vector. They store the vector along with the distinct values of the elements in the vector as labels. The labels are always character irrespective of the data type whether it is numeric or character or Boolean etc given in the input vector. They are useful in statistical modeling.

Factors are created using the function factor(). The n levels functions give the count of levels in the factor.

# Create a vector.
apple_colors 

When we execute the above code, it produces the following result

6) Data Frames

Data frames are tabular objects of data. Contrary to a matrix in data frame each column can contain different modes of data. Columns can be of different type like first column can be numeric while the second column can be character and third column can be logical. It can be said to be a list of vectors of equal length.

Data Frames are created using the function data.frame().

# Create the data frame.
BMI 

When we execute the above code, it produces the following result

Note: Examples of every data type are referenced from book and different sites.





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.


# Create a vector.
apple 

The above code, it produces the following result

2) Lists

A list is another R-object which can contain many different types of elements inside it like functions, vectors and even another list inside it.

# Create a list.
list1 

When we execute the above code, it produces the following result

3) Matrices

A matrix is a 2D rectangular data set. It can be created using a vector input which can be given to the matrix function.

# Create a matrix.
M = matrix( c('a','a','b','c','b','a'), nrow = 2, ncol = 3, byrow = TRUE)
print(M)

When we execute the code, it produces the following result

4) Arrays

While matrices are just upto two dimensions, arrays can be of any dimension. The array function takes a dim (dimension) attribute which creates the required number of dimension. In the example below we create an array with two elements which are 3x3 matrices each.

# Create an array.
a 

When we execute the above code, it produces the following result

5) Factors

Factors are other R-objects which are created using a vector. They store the vector along with the distinct values of the elements in the vector as labels. The labels are always character irrespective of the data type whether it is numeric or character or Boolean etc given in the input vector. They are useful in statistical modeling.

Factors are created using the function factor() . The n levels functions give the count of levels in the factor.

# Create a vector.
apple_colors 

When we execute the above code, it produces the following result

6) Data Frames

Data frames are tabular objects of data. Contrary to a matrix in data frame each column can contain different modes of data. Columns can be of different type like first column can be numeric while the second column can be character and third column can be logical. It can be said to be a list of vectors of equal length.

Data Frames are created using the function data.frame() .

# Create the data frame.
BMI 

When we execute the above code, it produces the following result

Note: Examples of every data type are referenced from book and different sites.





评论和讨论

广告:您是博主吗? 加入我们的Blogging论坛


翻译自: https://www.includehelp.com/r/data-types-in-r-programming-language.aspx

r语言是高级编程语言

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值