Data types and Data conversion in R
DATA TYPES IN R: There are 5 data types in R Programming.
1)Numeric: There are two types of numeric data Real number
/Double and Integer
A)REAL NUMBER/DOUBLE: (Example12,13.4,-2,-26.9)
A double allows you to store numbers as decimals. The double
precision number means they can store twice the information as
our integer. As well as storing decimal value. This means you can
store much bigger numbers with double than integers.
Example:
X<-13.5
typeof(X)
class(X)
mode(X)
B)INTEGER: (Example :6L, 34L)
If we provide “L” at the end of the number it becomes integer.
Example:
X<-13L
typeof(X)
class(X)
mode(X)
2)character: (Example: "A","TRUE","23.4","HELLO@23")
Any letters ,number, words with special charaters are present in
quotes that represent the character.
char<-"hello world"
typeof(char)
class(char)
mode(char)
3)Logical: TRUE OR FALSE
logi<-TRUE
typeof(logi)
class(logi)
mode(mode)
4)Complex; eg: 6+4i
comp<-6+4i
typeof(comp)
class(comp)
mode(comp)
5)RAW: Raw data is used to hold the raw bytes. It is rarely used.
Datatype Conversion in R : Data type conversion is the process of
converting one type of data to another type of data. There are 5
types of conversion in R datatypes:
1)numeric
2)character
3)complex
4)logical
1)Conversion into the numeric:
If we want to convert any data into numeric data then use key word
“[Link]”.
EXAMPLE
num1<-[Link](26L)
num1
class(num1)
num2<-[Link](26-45i)
num2
class(num2)
num3<-[Link](TRUE)
num3
class(num3)
num4<-[Link]("adrfg67")
num4
class(num4)
Note: If alphanumeric present in string then it cannot convert into
numeric but if either numeric or letters is present in string then it
convert into numeric
2)Conversion into integer: For conversion of integer data type use
keyword [Link].
EXAMPLE
int1<-[Link](34.980)
int1
int2<-[Link](45-56i)
int2
int3<-[Link]("123456")
int3
int4<-[Link]("3456gfr")
int4
3)Conversion of complex For conversion of integer data type use
keyword
[Link].
EXAMPLE:
com1<-[Link](45.678)
com1
com2<-[Link](45L)
com2
com3<-[Link](TRUE)
com3
com4<-[Link]("12356")
com4
4) Conversion Of logical datatype: For conversion of logical data
type use keyword [Link].
EXAPMLE:
logi1<-[Link](45.255)
logi1
logi2<-[Link](0)
logi2
logi3<-[Link](0+0i)
logi3
logi4<-[Link]("abght")
logi4
5)Conversion of character([Link])
char1<-[Link](45.098)
char1
char2<-[Link](45L)
char2
char3<-[Link](FALSE)
char3
char3<-[Link](2+3i)
char3