本体对象属性和数据属性区别_数据类型r对象和属性

本体对象属性和数据属性区别

In this article we’ll cover an important issue for R. We will talk about the different types of data used in R. We will also learn about some basic operations on data types.

在本文中,我们将介绍R的重要问题。我们将讨论R中使用的数据的不同类型。我们还将学习有关数据类型的一些基本操作。

如果您准备好了,那就开始吧: (If you’re ready, let’s get started:)

对象 (Objects)

Everything you manipulate in R, everything we encounter in R, objects that can be called objects, objects can all be of different types, contain all different types of data. But everything in R is an object. So R has five basic classes of atomic objects. These are fairly low levels or basic object classes, character, numeric. So these are like real numbers or decimal numbers, integers, complex numbers, and logicals

您在R中操作的所有内容,在R中遇到的所有内容,可以称为对象的对象,对象都可以具有不同的类型,包含所有不同类型的数据。 但是R中的所有东西都是对象。 因此,R具有原子对象的五种基本类别。 这些是相当低的级别或基本对象类,字符,数字。 所以这些就像实数或十进制数,整数,复数和逻辑

The most basic object in R is called a vector. One thing you cannot do with a standard vector is have mixed types of objects you cannot have a vector of characters and numerics, or numerics and integers, or integers and logicals. And everything in a vector has to be the same class.

R中最基本的对象称为向量。 标准向量不能做的一件事是具有混合类型的对象,您不能拥有字符和数字,数字和整数或整数和逻辑的向量。 向量中的所有内容都必须是同一类。

Somtimes there’s one type of vector that can have multiple different types of classes. This is a “list”. So a list is represent as a vector, it’s a sequence of objects. But each element of that vector can be a different and ofcourse can be an object of a different class. You can have a list that’s inside the list and one element of the list can be a data frame so, any element of the list can be anything. You can be created directly from expressions using the quote mechanism and converted to and from lists by the as.list and as.call functions.

有时,向量的一种类型可以具有多种不同类型的类。 这是一个“列表”。 因此,列表表示为向量,它是一系列对象。 但是该向量的每个元素可以不同,并且当然可以是不同类的对象。 您可以在列表内有一个列表,并且列表的一个元素可以是一个数据框,因此列表的任何元素都可以是任何东西。 可以使用引号机制从表达式直接创建您,并通过as.listas.call函数在列表之间进行转换。

Also you can create an empty vector with the vector function. And the vector function has two basic arguments. The first argument is the class of the object, so the type of object that you want to have in the vector. And the second argument is the length of the vector itself. R has six basic (‘atomic’) vector types: logical, integer, real, complex, string (or character) and raw. The modes and storage modes for the different vector types are listed in the following table.

您也可以使用矢量功能创建一个空矢量。 向量函数有两个基本参数。 第一个参数是对象的类,因此要在向量中包含的对象的类型。 第二个参数是向量本身的长度。 R具有六种基本(“原子”)向量类型:逻辑,整数,实数,复数,字符串(或字符)和原始。 下表列出了不同向量类型的模式和存储模式。

Image for post

号码 (Numbers)

Let’s come to the numbers as the most important object type. Numbers in R are generally treated as what are called numeric objectsum, so pretty much all numbers are treated as double number precision real numbers. So, even if you are looking at a number that’s like one or two, R thinks of those numbers as numeric objects there is a way to explicitly say you want an integer and you can specify the L subs, the L suf, the capital L suffix there. So for example, if you just enter the number 1 in R, that gives you a numeric object. But entering 1 with a capital L next to it explicitly gives you an integer. So, L specifies an integer type, rather than a double that the standard numeric class is.

让我们将数字作为最重要的对象类型。 R中的数字通常被视为数字对象和,因此几乎所有数字都被视为双精度数字实数。 因此,即使您正在寻找一个或两个类似的数字,R也会将这些数字视为数字对象,但是有一种方法可以明确地表示您想要一个整数,并且可以指定L个子,L suf和大写L后缀。 因此,例如,如果仅在R中输入数字1,则将为您提供数字对象。 但是,输入1并紧随其后的大写L会为您提供一个整数。 因此,L指定一个整数类型,而不是标准数字类的两倍。

> str(1)
num 1
> str(1L)
int 1

There’s a special inf, and inf is like a real number it can be used in calculations and you will get the expected result. So, for example, if you take one, divide it by zero, you’ll get infinity and if you take 1 and divide it by infinity you’ll get zero.

有一个特殊的inf,并且inf就像一个实数,可以在计算中使用,您将获得预期的结果。 因此,例如,如果乘以1,然后除以零,则将得到无穷大;如果乘以1,然后将其除以无穷,则将得到零。

nan means "not a number", a float value that you get if you perform a calculation whose result can't be expressed as a number. Any calculations you perform with NaN will also result in NaN.

nan意思是“不是数字”,这是一个浮点值,如果您执行其结果不能表示为数字的计算,则该值。 您使用NaN执行的任何计算也会产生NaN

inf means infinity. For example:

inf表示无穷大。 例如:

>>> 2*float("inf")
inf
>>> -2*float("inf")
-inf
>>> float("inf")-float("inf")
nan

属性 (Attributes)

Some of the most common types of attributes that we’ll encounter are names dimnames, dimensions, class, length, other user-defined attributes/ metadata. A dimension, so a matrix will have dimensions for example it will have a number of rows and a number of columns if you have a multidimensional array you’ll have more than two dimensions.

我们将遇到的一些最常见的属性类型是名称dimnames维,类,长度,其他用户定义的属性/元数据。 一个维度,因此矩阵将具有多个维度,例如,如果具有多维数组,它将具有多个行和多个列。

Every object have a class. So for example, numeric objects their class is numeric and integer objects, their class is integer.

每个对象都有一个。 因此,例如,数字对象的类为数字和整数对象,其类为整数。

studentBio <- list(studentName = "Tom Cruise", studentAge = 17, studentContact="New York") class(studentBio) <- "StudentInfo" studentBio$studentName
[1] "Tom Cruise"

$studentAge
[1] 19

$studentContact
[1] "New York"

attr(,"class")
[1] "StudentInfo"output:
$studentName
"Tom Cruise"

$studentAge
19

$studentContact
"New York"

attr(,"class")
"StudentInfo"

It is also necessary to know that every object has a length. Quite simply for a vector, the length of the object is the number of elements in the vector. There may also be other user-defined attributes or metadata that you can define individually for an object using various attribute functions. There is a generic function called attributes that allows you to set or change attributes() for an R object.

还必须知道每个对象都有一个长度。 对于向量来说,对象的长度就是向量中元素的数量。 您还可以使用其他属性功能为对象单独定义其他用户定义的属性或元数据。 有一个称为属性的通用函数,该函数使您可以设置或更改R对象的attribute()。

So we tried to briefly express a point on important objects and attributes. See you in the next post

因此,我们试图简要地表达关于重要对象和属性的观点。 下篇再见

翻译自: https://medium.com/swlh/data-types-r-objects-and-attributes-922427a7e0cc

本体对象属性和数据属性区别

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值