Data Types in R |R Programming

sanket-parate Trending Technology

This is the fourth part of the series. In this article, you will know about the data type of R Programming. Here all the functions that I have done in RGui.

Data Types in R:

1.Vectors: A Vector is a sequence of data elements of the same type. But you can mix objects of different classes too. To create a vector in R we use combine function. Here are some of examples.

# numeric vector
Numeric=c(1,2,3,4,5)

Output:

# character vector
s=c(“Ganesh”,”sukrati”)

Output:

# Boolean vector
Boolean=c(“True”, “False”)

Output:

To check the class of any object use class(vector name) function.
class(Numeric)

2.List: A list can store other objects including matrices, data frames and other lists. A list can be created using list() function.

#To create List:
p=list(Numeric,85,”ball”)

Output:

3.Matrices: A matrix is represented by set of rows and columns. It is a 2 dimensional data structure. It consists of elements of same class.

# create matrix
M=matrix(1:6,nrow=3, ncol=2,byrow=TRUE)

Output:

#To know about dimension of matrix:
dim(M)

Output:

#To Bind two columns:
x=c(7,8,9,10,11,12)
y=c(13,14,15,16,17,18)
cbind(x,y)

Output:

4.Data Frames: Data frame can store different data types. The data stored in a data frame can be of numeric or character type.

#To create data frame:
D=c(1,2,3)
E=c(4,5,6)
F=c(7,8,9)
LF=data.frame(D,E,F)

Output:

Sanket Parate

Tech enthusiast and an optimistic guy with the mindset to achieve the set target. I am an avid learner and passionate learner. After finding my interest in data science, I felt that 'Yes this is the field which I am looking for. I am more passionate to learn data science and R and looking forward to exploring more in these fields along with the python. I love to share information with people.

Leave a Reply

Your email address will not be published. Required fields are marked *