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对象。 常用的是:
Vectors
向量
Lists
清单
Matrices
矩阵
Arrays
数组
Factors
因素
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.
# 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.
翻译自: https://www.includehelp.com/r/data-types-in-r-programming-language.aspx
r语言是高级编程语言