0% found this document useful (0 votes)
9 views4 pages

A Data Structure Is A Particul

Uploaded by

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

A Data Structure Is A Particul

Uploaded by

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

A data structure is a particular way of organizing data in a

computer so that it can be used effectively. The idea is to reduce


the space and time complexities of different tasks. Data
structures in R programming are tools for holding multiple values.

R’s base data structures are often organized by their


dimensionality (1D, 2D, or nD) and whether they’re homogeneous
(all elements must be of the identical type) or heterogeneous (the
elements are often of various types). This gives rise to the six
data types which are most frequently utilized in data analysis.

Vectors
A vector is an ordered collection of basic data types of a given
length. The only key thing here is all the elements of a vector
must be of the identical data type e.g homogeneous data
structures. Vectors are one-dimensional data structures.

Example:

# R program to illustrate Vector

# Vectors(ordered collection of same data type)


X = c(1, 3, 5, 7, 8)

# Printing those elements in console


print(X)
Output:

[1] 1 3 5 7 8

Lists
A list is a generic object consisting of an ordered collection of
objects. Lists are heterogeneous data structures. These are also
one-dimensional data structures. A list can be a list of vectors, list
of matrices, a list of characters and a list of functions and so on.

Example
# R program to illustrate a List

# The first attributes is a numeric vector


# containing the employee IDs which is
# created using the 'c' command here
empId = c(1, 2, 3, 4)

# The second attribute is the employee name


# which is created using this line of code here
# which is the character vector
empName = c("Debi", "Sandeep", "Subham", "Shiba")

# The third attribute is the number of employees


# which is a single numeric variable.
numberOfEmp = 4

# We can combine all these three different


# data types into a list
# containing the details of employees
# which can be done using a list command
empList = list(empId, empName, numberOfEmp)

print(empList)

Output:

[[1]]
[1] 1 2 3 4

[[2]]
[1] "Debi" "Sandeep" "Subham" "Shiba"

[[3]]
[1] 4
Dataframes
Dataframes are generic data objects of R which are used to store
the tabular data. Dataframes are the foremost popular data
objects in R programming because we are comfortable in seeing
the data within the tabular form. They are two-dimensional,
heterogeneous data structures. These are lists of vectors of equal
lengths.

Data frames have the following constraints placed upon them:

A data-frame must have column names and every row should


have a unique name.
Each column must have the identical number of items.
Each item in a single column must be of the same data type.
Different columns may have different data types.
To create a data frame we use the data.frame() function.

Example:

# R program to illustrate dataframe

# A vector which is a character vector


Name = c("Amiya", "Raj", "Asish")

# A vector which is a character vector


Language = c("R", "Python", "Java")

# A vector which is a numeric vector


Age = c(22, 25, 45)

# To create dataframe use data.frame command


# and then pass each of the vectors
# we have created as arguments
# to the function data.frame()
df = data.frame(Name, Language, Age)

print(df)

Output:

Name Language Age


1 Amiya R 22
2 Raj Python 25
3 Asish Java 45

You might also like