Data Structure in R

Overview

R中的一些数据结构,以及mode, class, typeof的区分。

Data Structure

R has a wide variety of objects for holding data, including scalars, vectors, matrices, arrays, data frames, and lists. They differ in terms of the type of data they can hold, how they’re created, their structural complexity, and the notation used to identify and access individual elements.

有一点值得注意,那就是vector, matrix和array都必须是single mode,也就是只能储存同种类型的数据。而data.frame却更加包容:different columns can contain dif- ferent modes

特别地,R中有两个比较特别的数据类型:factor和list。对于factor:Categorical (nominal) and ordered categorical (ordinal) variables in R are called factors.对于list:Lists are the most complex of the R data types. Basically, a list is an ordered collection of objects (components). A list allows you to gather a variety of (possibly unrelated) objects under one name.两者都算是R特有的数据类型了,而且在之后的学习中也会发现其为我们的分析提供了极大的便利。

class, mode and typeof

class

class返回对象的抽象类型(如data.frame), 可以用来指示一些generic function怎样去处理这个对象。

class represents its abstract type, which tells generic functions like print how to handle it)

mode

简单讲,mode是返回对象在内存中是以何种方式储存的。

mode represents how an object is stored in memory (numeric, character, list and function).

Function mode gives information about the mode of an object in the sense of Becker, Chambers & Wilks (1988), and is more compatible with other implementations of the S language

typeof

返回对象的数据类型。

The R specific function typeof returns the type of an R object.

mode vs typeof

mode and storage.mode are the old-style types (where storage.mode is more accurate), and typeof is the newer, even more accurate version.

解释的很清楚了,mode是比较旧的用法,用来查看存储的方式,而且它不如storage.mode精确,但是它和S语言有更好的兼容性。而typeof是新的用法,可以更加精确地查看对象的存储方式。所以…现在一般用typeof看下类型就行了。

参考

stackoverflow1

stackoverflow2

stackexchange

R Language Definition

本文标题:Data Structure in R

文章作者:不秩稚童

发布时间:2017年10月10日 - 12:06:26

最后更新:2017年10月10日 - 13:54:53

原始链接:http://datahonor.com/2017/10/10/Data-Structure-in-R/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

击蒙御寇