0% found this document useful (0 votes)
23 views

1c Objects Attributes

R has five basic classes of objects: character, numeric, integer, complex, and logical. The most basic object is a vector, which can only contain elements of the same class except lists, which can contain different classes. Numbers are generally treated as numeric objects but integers can be specified with an L suffix. There are special numbers like Inf representing infinity and NaN representing undefined values. R objects can have attributes like names, dimensions, class and length that provide additional information and can be accessed with the attributes() function.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

1c Objects Attributes

R has five basic classes of objects: character, numeric, integer, complex, and logical. The most basic object is a vector, which can only contain elements of the same class except lists, which can contain different classes. Numbers are generally treated as numeric objects but integers can be specified with an L suffix. There are special numbers like Inf representing infinity and NaN representing undefined values. R objects can have attributes like names, dimensions, class and length that provide additional information and can be accessed with the attributes() function.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Objects

R has five basic or atomic classes of objects:


character
numeric (real numbers)
integer
complex
logical (True/False)
The most basic object is a vector
A vector can only contain objects of the same class
BUT: The one exception is a list, which is represented as a vector but can contain objects of
different classes (indeed, thats usually why we use them)
Empty vectors can be created with the vector() function.

2/27

Numbers
Numbers in R a generally treated as numeric objects (i.e. double precision real numbers)
If you explicitly want an integer, you need to specify the L suffix
Ex: Entering 1 gives you a numeric object; entering 1L explicitly gives you an integer.
There is also a special number Inf which represents infinity; e.g. 1 / 0; Inf can be used in
ordinary calculations; e.g. 1 / Inf is 0
The value NaN represents an undefined value (not a number); e.g. 0 / 0; NaN can also be
thought of as a missing value (more on that later)

3/27

Attributes
R objects can have attributes
names, dimnames
dimensions (e.g. matrices, arrays)
class
length
other user-defined attributes/metadata
Attributes of an object can be accessed using the attributes() function.

4/27

You might also like