0% found this document useful (0 votes)
3 views10 pages

Dar 5 Lec

The document outlines the various data types in R, including vectors, lists, matrices, arrays, factors, and data frames. It details the characteristics of logical, numeric, integer, character, double, complex, and raw data types, along with examples of their usage and classification. Additionally, it discusses coercion, which allows for the conversion between different data types.

Uploaded by

sharmahemant3610
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views10 pages

Dar 5 Lec

The document outlines the various data types in R, including vectors, lists, matrices, arrays, factors, and data frames. It details the characteristics of logical, numeric, integer, character, double, complex, and raw data types, along with examples of their usage and classification. Additionally, it discusses coercion, which allows for the conversion between different data types.

Uploaded by

sharmahemant3610
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Data types in R

Compiled and Presented by:


Dr.Chetna Arora
The most popular (based on usage)
R objects

• Vector
• List
• Matrix
• Array
• Factor
• Data Frames
Data types supported by R

• Logical
• Numeric
• Integer
• Character
• Double
• Complex
• Raw
Logical
TRUE / T and FALSE / F are logical > FALSE
values. [1] FALSE
> TRUE > class(FALSE)
[1] TRUE [1] "logical"
> class(TRUE) >F
[1] "logical" [1] FALSE
>T > class(F)
[1] TRUE [1] "logical.
> class(T)
[1] "logical"
Numeric

•>2
• [1] 2
• > class (2)
• [1] "numeric"
• > 76.25
• [1] 76.25
• > class(76.25)
• [1] "numeric
Integer
Integer data type is a sub class of numeric data
type. Notice the use of “L“ as a suffix to
a numeric value in order for it to be considered
an “integer”.
> 2L
[1] 2 Functions such as is.numeric(), is.integer() can
> class(2L) be used to test the data type.
[1] "integer" > is.numeric(2)
[1] TRUE
> is.numeric(2L)
[1] TRUE
> is.integer(2)
[1] FALSE
> is.integer(2L)
[1] TRUE
Note: Integers are numeric but NOT all
numbers are integers
Character

• > "Data Science"


• [1] "Data Science"
• > class("Data Science")
• [1] "character"
• is.character() function can be used to ascertain if a value is a character.
• > is.character ("Data Science")
• [1] TRUE
• Double (for double precision floating point numbers)
• By default, numbers are of “double” type unless explicitly mentioned with an L suffixed
• to the number for it to be considered an integer.
• > typeof (76.25)
• [1] "double"
Complex

• > 5 + 5i
• [1] 5+5i
• > class(5 + 5i)
• [1] "complex
Raw

• > charToRaw("Hi")
• [1] 48 69
• > class (charToRaw ("Hi"))
• [1] "raw"
Coercion

• Coercion helps to convert one data type to another, e.g.


logical “TRUE” value when
• converted to numeric yields “1”. Likewise, logical
“FALSE” value yields “0 ”.
• > as.numeric(TRUE)
• [1] 1
• > as.numeric(FALSE)
• [1] 0coercion

You might also like