0% found this document useful (0 votes)
60 views2 pages

ST 104-Rstudio Exercise03

This document outlines exercises involving analyzing a baseball player salary data set and performing operations on matrices. It includes instructions to name columns in the data set, calculate summary statistics on salaries by position, add a new coded salary column, create a bar chart of position and salary codes, sort the data by salary, count players by team with loops, and write functions to calculate the trace of a 2x2 matrix and compute factorials.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views2 pages

ST 104-Rstudio Exercise03

This document outlines exercises involving analyzing a baseball player salary data set and performing operations on matrices. It includes instructions to name columns in the data set, calculate summary statistics on salaries by position, add a new coded salary column, create a bar chart of position and salary codes, sort the data by salary, count players by team with loops, and write functions to calculate the trace of a 2x2 matrix and compute factorials.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

ST 104- RSTUDIO

Exercise03

1) Consider the baseball_data.txt file in the course home page.


Variables
Team
Name
Salary
Position

description
Team of the each player. There are 14 teams
Name of the each player
Salary of the each player per year in US
Dollars
Position of the each player.

a)
I.
II.
III.
IV.
V.
VI.
VII.
VIII.
IX.

Name columns as per the above table.


What is the average salary of a baseball player?
What is the average salary of a player got who is in the position of pitcher?
What is the maximum salary of the position of second baseman?
What is the average salary of a player in the position of outfielder?
Which team has paid the minimum, average salary?
How many pitches in the Anahelm Angles team?
Which team have the maximum out fielders?
Obtain a subset which have a salary greater than 7500000 and the position of pitcher.

b)
I.

Code the data as follows then add the new column to the data frame. Hint: use a for
loop.
Original value
Salary 0-500000 $
Salary above 500000$

II.
III.
IV.
V.

Coded value
0
1

Hence draw a stack bar chart for the position and the code variable.
Sort the data set based on the salary.
Count the number of players which are from the Boston Red Sox team using a loop.
Count the number of players from other than New York Yankees.

ST 104- RSTUDIO
Exercise03

2)
I.
II.
III.

Write a function to obtain the trace of a 2x2 matrix. The trace of a matrix is the sum of
the diagonal elements of that matrix.
Hence calculate the trace of the following matrix.
2 3
[
]
4 5
Write a R function to calculate the factorial values.

You might also like