100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Summary

Summary Solutions Exercises R lab sessions

Rating
-
Sold
-
Pages
24
Uploaded on
22-12-2023
Written in
2023/2024

In this document you can find all the solutions of the lab sessions in R for Business Engineer second bachelor.

Institution
Course










Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Study
Course

Document information

Uploaded on
December 22, 2023
Number of pages
24
Written in
2023/2024
Type
Summary

Subjects

Content preview

Exercises: solutions: Introduction
Google is your best friend:

max(1,20,15,13,17,18,12,5)

2.3.1 Som van integers 1,…,100

100*(100+1)/2

2.3.2 Som van integers 1,…,1000

1000*(1000+1)/2

2.3.3 Interpreteer code

2

Functions

x <- c(5,6,1,2)

Geneste functies

log10(sqrt(100))

Variables in a dataframe

2

Variables names

# Load package and data

library(ISLR2)

data(Hitters)

names(Hitters)

# Use the function names to extract the variable names

Examining variables

# Load package and data

library(ISLR2)

data(Hitters)



# Use the accessor to extract Hits and assign it to the object a

a <- Hitters$Hits

# Determine the class of a

class(a)

Multiple ways to access variables

, # Load package and data

library(ISLR2)

data(Hitters)



# Use the accessor to extract Hits and assign it to a

a <- Hitters$Hits

# Use the square brackets to extract Hits and assign it to b

b <- Hitters[["Hits"]]

# Check if a and b are identical

identical(a,b)

Factors

# Load package and data

library(ISLR2)

data(Hitters)



# Determine the number of Leagues included in this variable

a <- Hitters$League

b <- levels(a)

length(b)

Tables

# Load package and data

library(ISLR2)

data(Hitters)

# Calculate the number of players per League using the table() function

table(Hitters$League)

Matrices 1

x <- matrix(c(7,8,5,3), 2, 2)

Matrices 2

x <- matrix(data= c(1,2,3,4), nrow =2, ncol = 2, byrow = TRUE)

Matrices 3

x <- matrix(data = c(1, 2, 3, 4), nrow = 2, ncol = 2)

, x.sqrt <- sqrt(x)

x.squared <- x^2

Indexing matrices 1

A <- matrix (1:16, 4, 4)

A1 <- A[1:3, 1:3]

A2 <- A[c(1,3),c(2,4)]

A3 <- A[2,4]

A4 <- A[,4]

A5 <- A[1,]+A[2,]

Indexing matrices 2

B <- matrix(1:8, 4, 2)

dim(B)

2.8.1-5. Vectoren

temp <- c(35,88,42,84,81,30)

city <- c("Beijing","Lagos","Paris","Rio de Janeiro","San Juan","Toronto")

named_temp <- temp

names(named_temp) <- city

temp_13 <- named_temp[1:3]

temp_ps <- named_temp[c("Paris","San Juan")]

2.8.6. Vector van getallen 12..73

12:73

Sequencing

x1 <- seq(5,10)

x2 <- seq(1,10, length = 4)

x3 <- seq(10,25,5)

2.8.7. Oneven getallen

seq(1,100,2)

Adding vectors and vector length

x <- c(1, 6, 2)

y <- c(1, 4, 3)

x.length <- length(x)
$7.42
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
Worstje2021
5.0
(1)

Get to know the seller

Seller avatar
Worstje2021 Universiteit Gent
Follow You need to be logged in order to follow users or courses
Sold
7
Member since
2 year
Number of followers
5
Documents
13
Last sold
1 year ago

5.0

1 reviews

5
1
4
0
3
0
2
0
1
0

Recently viewed by you

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

Frequently asked questions