0% found this document useful (0 votes)
4 views

1.4 Getting Data Into R 2

Chapter 1 introduces R programming for data science, focusing on creating and manipulating vectors, factors, and lists. Vectors are one-dimensional arrays for storing data, while factors categorize data with limited values, and lists can hold different data types. The chapter also covers basic operations on vectors and emphasizes the differences between these data structures.

Uploaded by

masao1268
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

1.4 Getting Data Into R 2

Chapter 1 introduces R programming for data science, focusing on creating and manipulating vectors, factors, and lists. Vectors are one-dimensional arrays for storing data, while factors categorize data with limited values, and lists can hold different data types. The chapter also covers basic operations on vectors and emphasizes the differences between these data structures.

Uploaded by

masao1268
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 21

Chapter 1:

Introduction to R Programming
for Data Science
Getting Data into R 2
Objective
 Create vectors in the R programming language,
 Create factors in the R programming language,
 Create a list in the R programming language,
 Access and modify the list elements.

3
Vector
 A vector is a one-dimensional array of objects, used for storing
data.
 Create vectors in R

Function Example Result


c(x,y) 5134
x:y 3456
seq(from, to, by, length.out) 13579
rep(x, times, each, 335533
length.out) 55

4
Vector
Create vectors in R: using c()

5
Vector
 Create vectors in R: using a:b
a:b function takes two numeric scalars a and b as arguments,
and returns a vector of numbers from the starting point a to
the ending point b in steps of 1
 Example

6
Vector
 Create vectors in R: using seq()
seq(): create a sequence from a starting number to an ending
number
Argument Definition
from The start of the sequence
to The end of the sequence
by The step-size of the sequence
The desired length of the final sequence (only use if you don’t
length.out
specify by)

7
Factors
 Factor in R is a variable used to categorize and store the data, having a limited
number of different values. It can stores both string and integer data values as
levels.
 They are useful in data analysis for statistical modeling.
 Syntax
factor(x = character(), levels, labels = levels, ordered = is.ordered(x))

8
Factors

9
Vector Operations

11
Vector Operations

12
Vector Operations

13
Arithmetic operations on vectors
Arithmetic operations on vectors
 Basic arithmetic operations: +, -, *
 Example

14
Vector Operations

15
Lists
 is a collection of objects in which the elements inside can
differ in terms of data type

16
Lists

17
Lists

18
Lists

Chapter1- Importing Datasets 19


Lists

20
Summary
 At this point in the course, you know:
• A vector is a string of numbers, characters, or logical data.
• Factors (also known as categorical variables) are variables that take on
a limited number of different values that can be nominal or ordinal.
• You can use R to perform operations on a vector, such as sorting the
items, finding the smallest or largest number, or performing arithmetic
on its values.
• Lists can store different types of data, unlike vectors, which can only
store data of a single type.

21
Q&A

Chapter1- Importing Datasets 22

You might also like