r语言假设检验的示例数据_带有R语言示例的数据类型

r语言假设检验的示例数据

Traditionally, while programming in any programming language the programmer needs to take the help of several available variables to store the distinct information in them. When the variables are considered, in simple terms, they are defined as the store places for storing the data of various types. The variables are generally used to store the data as they possess the reserved memory locations to preserve the values. In simple words, we can define the variables as the memory locations which when created reserve some space for storing some values in them.

传统上,在使用任何编程语言进行编程时,程序员都需要借助几个可用变量来在其中存储不同的信息。 简单地考虑变量时,将它们定义为用于存储各种类型数据的存储位置。 变量通常用于存储数据,因为它们拥有保留的存储位置以保存值。 简而言之,我们可以将变量定义为存储位置,这些位置在创建时会保留一些空间以在其中存储一些值。

Fine, we learned the fact that the variables are commonly used to store the data. But we humans wish to store data of various types like sometimes characters, integers, wide characters, floating points, Double floating points, long integers, unsigned numbers, signed numbers, boolean, etc. Now based on our requirements we need to access the different types of data types. Now based on the type of data type the operating system takes the responsibility of allocating the memory to the variables and decides on the matters like which data must be stored into the reserved memory.

很好,我们了解到以下事实:变量通常用于存储数据。 但是我们人类希望存储各种类型的数据,例如有时字符,整数,宽字符,浮点数,双浮点数,长整数,无符号数,有符号数,布尔值等。现在,根据我们的要求,我们需要访问不同的数据数据类型的类型。 现在,基于数据类型,操作系统负责将内存分配给变量,并决定诸如必须将哪些数据存储到保留内存之类的事项。

In contrast to the other programming languages like the C and the Java, in the R language, the variables are not declared with the data types. Here in the R language, the R objects are used for the declaration of the variables. Hence the data type of the declared R object becomes the data type of the considered variable. The data objects that are included in the R languages are many. Therefore on attempting to list out some of them, we obtain the below list:

与其他编程语言(如C和Java)相反,在R语言中,变量未使用数据类型声明。 在这里,用R语言,R对象用于变量的声明。 因此,已声明的R对象的数据类型成为所考虑变量的数据类型。 R语言中包含的数据对象很多。 因此,在尝试列出其中一些时,我们获得以下列表:

数据类型列表 (List of Data Types)

  1. Vectors

    向量

  2. Arrays

    数组

  3. Lists

    清单

  4. Factors

    因素

  5. Matrices

    矩阵

  6. Data frames

    数据框

Among the above objects, the simplest of all of them is a vector object. Moreover, there are other six atomic objects which are mainly useful in building the R objects. They are,

在上述所有对象中,最简单的是矢量对象。 此外,还有其他六个原子对象,它们主要用于构建R对象。 他们是,

  1. Logical

    逻辑上

  2. Integer

    整数

  3. Numeric

    数字

  4. Character

    字符

  5. Complex

    复杂

  6. Raw

    生的

Thus, as stated earlier, working with the vectors is the simplest way that makes the user very comfortable while coding. The vectors consist of the above-mentioned classes. One of the specialties of the R language is that the digit of classes is not constrained to merely above the six categories. Since they are numerous types, which are used by the programmer based on the requirements in the code.

因此,如前所述,使用向量是使用户在编码​​时感到非常舒适的最简单方法。 向量由上述类组成。 R语言的特色之一是类别的位数不仅仅局限于六个类别。 由于它们是多种类型,因此程序员将根据代码中的要求使用它们。

Before the article, we have seen the different types of data types that are exclusively available in the R language. In simple words, the data types are assigned to the variables. Thus, these data types give a command to the operating system to store the data that matches the declared data type. The variables are ought to store the particular data which resembles the declared data types while the declaration of variables is done. But here we need to note an important point that in the R language the programmer needs to store the data in a variable with the help of objects that are available in the R language. Thus, through this we can make sure that the variables declared in the R language are assigned with the help of R objects. Whatever the R object is assigned to a variable then that becomes the data type of that particular variable. However, there are many more R objects available but the usage of them mainly depends on the requirement in the program.

在本文之前,我们已经看到了R语言专有的不同类型的数据类型 。 简而言之,将数据类型分配给变量。 因此,这些数据类型向操作系统发出命令以存储与声明的数据类型匹配的数据。 变量声明完成后,变量应存储类似于声明的数据类型的特定数据。 但是这里我们需要注意一个重要的点,在R语言中,程序员需要借助R语言中可用的对象将数据存储在变量中。 因此,通过这种方式,我们可以确保在R语言声明的变量的帮助下使用R对象。 无论将R对象分配给变量如何,它都将成为该特定变量的数据类型。 但是,还有更多的R对象可用,但是它们的用法主要取决于程序中的要求。

Some common data structures and their workings,

一些常见的数据结构及其工作原理,

1)向量 (1) Vectors)

Sometimes we require a variable such that we need to accommodate several items under the same attribute. In such a case, we opt for these vectors. Whenever one likes to create a vector that encompasses more than a single element in them then one should use the c() function. This function stands responsible for combining elements into a declared variable which is of type vector.

有时我们需要一个变量,以便我们需要在同一属性下容纳多个项目。 在这种情况下,我们选择这些向量。 每当有人喜欢创建一个包含多个元素的向量时,都应该使用c()函数。 该函数负责将元素组合到一个声明的变量中,该变量的类型为vector。

Example:

例:

# Create a vector.
apple <- c('red','green',"yellow")
print(apple)

# Get the class of the vector.
print(class(apple))

Output

输出量

[1] "red"    "green"  "yellow"
[1] "character"

2)矩阵 (2) Matrices)

Usually, the matrix is a 2-dimensional data set that takes the shape of a rectangle. The matrix variable is created with the help of vector input to the desired matrix function.

通常,矩阵是采用矩形形状的二维数据集。 矩阵变量是通过将矢量输入到所需矩阵函数的方式创建的。

Example:

例:

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

Output

输出量

     [,1] [,2] [,3]
[1,] "a"  "a"  "b" 
[2,] "c"  "b"  "a" 

3)清单 (3) Lists)

In general, the word list gives us the impression that it contains several items of either the same category or different types In a similar fashion, the Lists in the R language also contain the various types of elements like function, vectors and sometimes there will be a list present in a single list. The below code is an example of the demonstrations of the concept of lists in the R language.

通常,单词列表给我们的印象是,它包含多个相同类别或不同类型的项。以类似的方式,R语言中的列表还包含各种类型的元素,例如函数,向量,有时还会存在于单个列表中的列表。 以下代码是R语言中的列表概念演示的示例。

Example:

例:

# Create a list.
list1 <- list(c(2,5,3),21.3,sin)
# Print the list.
print(list1)

Output

输出量

[[1]]
[1] 2 5 3

[[2]]
[1] 21.3

[[3]]
function (x)  .Primitive("sin")

Here the above text has dealt with some of the data types that are mainly used in the R language.

在此,上面的文本处理了一些主要用于R语言的数据类型。

4)数组 (4) Arrays)

Arrays can possess any number of dimensions rather than that of the matrix. The arrays function in the R language considers the dim attribute that eventually creates the number of dimensions based on the user request.

数组可以拥有任意数量的维度,而不是矩阵。 R语言中的arrays函数考虑dim属性,该属性最终根据用户请求创建维数。

The below example creates an array with the help of two elements which are arranged in the form of 3×3 matrices.

以下示例借助两个以3×3矩阵形式排列的元素创建一个数组。

Example:

例:

# Create an array.
a <- array(c('green','yellow'),dim = c(3,3,2))
print(a)

Output

输出量

, , 1

     [,1]     [,2]     [,3]    
[1,] "green"  "yellow" "green" 
[2,] "yellow" "green"  "yellow"
[3,] "green"  "yellow" "green" 

, , 2

     [,1]     [,2]     [,3]    
[1,] "yellow" "green"  "yellow"
[2,] "green"  "yellow" "green" 
[3,] "yellow" "green"  "yellow"

5)因素 (5) Factors)

The factors are also created by using vectors only. The only difference is that the factors store the vectors along with the different values of the elements in the created variable that resembles a vector. The values in the vectors are stored as labels. However, the vectors are perpetually characters irrespective of the type they take up as they may be numeric, boolean, or character. But indeed they are taken as a character in the vector considered. These factors are useful in Statistical modeling. The function factor() is used for creating the factors. The nlevels is the function which enables the programmer or the user to count the levels available in the particular program.

也仅通过使用向量来创建因子。 唯一的区别是因素将向量以及元素的不同值存储在类似于向量的已创建变量中。 向量中的值存储为标签。 但是,向量是永久字符,而与它们所使用的类型无关,因为它们可能是数字,布尔值或字符。 但是实际上,它们被视为所考虑向量中的一个字符。 这些因素在统计建模中很有用。 函数factor()用于创建因子。 nlevels是使程序员或用户能够计算特定程序中可用级别的功能。

The following code will help you in understanding the above statements very clearly.

以下代码将帮助您非常清楚地理解上述陈述。

Example:

例:

# Create a vector.
apple_colors <- c('green','green','yellow','red','red','red','green')

# Create a factor object.
factor_apple <- factor(apple_colors)

# Print the factor.
print(factor_apple)
print(nlevels(factor_apple))

Output

输出量

[1] green  green  yellow red    red    red    green 
Levels: green red yellow
[1] 3

6)数据框 (6) Data Frames)

Generally, the data frames are known to be the tabular data objects that fall under the above category. In these data frames, each frame consists of various modes of values. For example, the first column can be of numeric type, and then the next one may be of a character and so on.

通常,已知数据帧是属于上述类别的表格数据对象。 在这些数据帧中,每个帧都包含各种模式的值。 例如,第一列可以是数字类型,然后第二列可以是字符,依此类推。

The function which enables the user to create a data frame is the data.frame() function.

使用户能够创建数据帧的函数是data.frame()函数。

Example:

例:

# Create the data frame.
BMI <-   data.frame(
   gender = c("Male", "Male","Female"), 
   height = c(152, 171.5, 165), 
   weight = c(81,93, 78),
   Age = c(42,38,26)
)
print(BMI)

Output

输出量

  gender height weight Age
1   Male  152.0     81  42
2   Male  171.5     93  38
3 Female  165.0     78  26


翻译自: https://www.includehelp.com/r/data-types-with-examples.aspx

r语言假设检验的示例数据

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值