• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 10 pages
Exam (elaborations)

Data_Mining_&_Statistical_Modeling_Week1_Introduction_to_R

Document preview thumbnail
Preview 2 out of 10 pages

Replicate the textbook's code shown in Chapter 2 (2.3 Lab: Introduction to R). 2.3 Lab: Introduction to R In this lab, we will introduce some simple R commands to understand how R works. 2.3.1 Basic Commands 2.3.2 Graphics 2.3.3 Indexing Data 2.3.4 Loading Data

Content preview

Intro_to_R
John Doe

2025-06-05

2.3 Lab: Introduction to R


In this lab, we will introduce some simple R commands to understand
how R works.
2.3.1 Basic Commands
# Creating a numeric vector with 4 elements
x <- c(1, 3, 2, 5)

# Printing the vector x
x

## [1] 1 3 2 5

# Updating x with a new set of values
x = c(1, 6, 2)

# Printing the updated x
x

## [1] 1 6 2

# Creating another numeric vector with 3 elements
y= c(1, 4, 3)


# Checking the number of elements in x
length(x)

## [1] 3

# Trying to find the length of y (this will give an error because y
doesn't exist yet)
length(y)

## [1] 3

# Adding x and y (will also give an error unless y is defined)
x + y

## [1] 2 10 5

, # Listing all current objects in the environment
ls()

## [1] "x" "y"

# Removing objects x and y from the environment
rm(x, y)

# Checking again to confirm they are removed
ls()

## character(0)

# Removing everything from the environment
rm(list = ls())

# Asking for help on the matrix function
?matrix

## starting httpd help server ... done

# Creating a 2x2 matrix using named arguments
x <- matrix(data = c(1, 2, 3, 4), nrow = 2, ncol = 2)
x

## [,1] [,2]
## [1,] 1 3
## [2,] 2 4

# Creating a matrix without naming the arguments (just positional)
x <- matrix(c(1, 2, 3, 4), 2, 2)

# Creating a matrix where values are filled by row instead of column
matrix(c(1, 2, 3, 4), 2, 2, byrow = TRUE)

## [,1] [,2]
## [1,] 1 2
## [2,] 3 4

# Taking square root of each element in x
sqrt(x)

## [,1] [,2]
## [1,] 1.000000 1.732051
## [2,] 1.414214 2.000000

# Squaring each element in x
x^2

## [,1] [,2]
## [1,] 1 9
## [2,] 4 16

Connected book
 image
Gareth James, Daniela Witten, Trevor Hastie, Robert Tibshirani An Introduction to Statistical Learning
Publisher: 2013 ISBN: 9781461471387 Edition: Unknown

Document information

Uploaded on
June 5, 2025
Number of pages
10
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$10.98

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
datascience24
4.5
(12)
Sold
87
Followers
16
Items
159
Last sold
4 months ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions