5 Data Type

  • Integer
  • Double or Float
  • Character or String
  • Boolean or Logical

5.1 R atomic class

Class Concept Example
integer Integer 1L; -5L
double Double 1.0; 3.14; 5.3E-12; 22/7
character Character 'a'; 'A'; 'Sam'; 'David'; '2'; 'This is a character variable'
logical Logical a = 3 > 4; T; F; TRUE; FALSE; True; False
typeof, class Find type (class) of variable typeof(x); typeof(y); class(z); class(z)
is.integer Boolean check: integer is.integer(x)
is.double Boolean check: double is.double(x)
is.character Boolean check: character is.character(x)
is.logical Boolean check: logical is.logical(x)

5.2 R Example

x = 5L; y = 5.3; z = 'Sam'; w = TRUE

typeof(x); typeof(y); typeof(z); typeof(w)

[1] “integer” [1] “double” [1] “character” [1] “logical”

class(x); class(y); class(z); class(w)

[1] “integer” [1] “numeric” [1] “character” [1] “logical”


5.3 Python

Type Concept Example
int Integer 1L; -5L
float Double 1.0; 3.14; 5.3E-12; 22/7
str, chr Character 'a'; 'A'; 'Sam'; 'David'; '2'; 'This is a string variable'
bool Logical a = 3 > 4; True; False
type Find type of variable type(x); type(y); type(z); type(z)
is.instance Boolean check: integer is.instance(x, int)
Boolean check: float is.instance(x, float)
Boolean check: string is.instance(x, str)
Boolean check: boolean is.instance(x, bool)

5.4 Python Example


x = 5; y = 5.3; z = 'Sam'; w = True

type(x); type(y); type(z); type(w)

<class ‘int’> <class ‘float’> <class ‘str’> <class ‘bool’>