You are on page 1of 1

# Comments for Windows-Users

# First, create the folder StatBA (case sensitive) on your C drive.

# Set working directory of R to StatBA


setwd("C:/StatBA")

# Control the working directory in R


getwd()
# The result should be C:/StatBA

#---------------------------------------------------------
# Exercise R.3

# Save R3.csv in the folder StatBA

# Save the data to the variable "dat"


dat <- read.csv(file = "R3.csv")

# or
dat <- read.table(file = "R3.csv", header = TRUE, sep = ",")

# head() and tail()


head(dat)
summary(dat)

# Minimum und Maximum of Observations


range(dat)

# or
min(dat)
max(dat)

# Empirical mean of the third column


mean(dat[, 3])

# Observations larger than 3


index <- which(dat > 3, arr.ind = TRUE)

# Control
dat[index]

#---------------------------------------------------------
# Exercise R.4

# First install the package "UsingR" in R


# This should be done only one time, if you have never used this package before
# Afterwards comment this R-command with "#" as it is shown below

install.packages("UsingR")
#install.packages("UsingR")

# Load the package "UsingR"


library(UsingR)

# To see the variable (column) names of the data set "MLBattend"


names(MLBattend)
# To see the first rows of the data set "MLBattend
head(MLBattend)

# Assign the number of wins of the team NY Yankees to the variable wins.nya
wins.nya <- MLBattend$wins[MLBattend$franchise == "NYA"]
wins.nya

names(wins.nya) <- 1969:2000


wins.nya

# Bar plot and dot chart in one plot device


par(mfrow = c( 1, 2 ))

barplot(wins.nya, xlab = "Year", ylab = "Number of wins", main = "Wins of NY Yankees")


dotchart(wins.nya, xlab = "Number of wins",ylab = "Year", main = "Wins of NY Yankees")

You might also like