This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.
Oscar Alexnader Tobar
COURSE: CAP4936-2253-4282
plot(cars)
Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Ctrl+Alt+I.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.
Suppose you are the General Manager of a baseball team, and you are selecting two players for your team. You have a budget of $10,500,000, and you have the choice between the following players: Player Name OBP SLG Salary Yandy Diaz 0.403 0.511 $8,000,000 Joey Meneses 0.320 0.366 $723,600 Jose Abreu 0.292 0.358 $19,500,000 Ryan Noda 0.384 0.400 $720,000 Nate Lowe 0.365 0.426 $4,050,000
Given your budget and the player statistics, which two players would you select?
df = read.csv("In class acitivty 9 csv file.csv")
str(df)
'data.frame': 5 obs. of 4 variables:
$ Player.Name: chr "Yandy Diaz" "Joey Meneses" "Jose Abreu" "Ryan Noda" ...
$ OBP : num 0.403 0.32 0.292 0.384 0.365
$ SLG : num 0.511 0.366 0.358 0.4 0.426
$ Salary : chr "$8,000,000 " "$723,600 " "$19,500,000 " "$720,000 " ...
summary(df)
Player.Name OBP SLG Salary
Length:5 Min. :0.2920 Min. :0.3580 Length:5
Class :character 1st Qu.:0.3200 1st Qu.:0.3660 Class :character
Mode :character Median :0.3650 Median :0.4000 Mode :character
Mean :0.3528 Mean :0.4122
3rd Qu.:0.3840 3rd Qu.:0.4260
Max. :0.4030 Max. :0.5110
library(dplyr)
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
select(df, Salary, Player.Name, OBP, SLG)
10500000 - 8000000 - 720000
[1] 1780000
We would have $1780000 left after selecting Yandy Diaz and Joey Meneses
These maybe the best options according to the OBP and SLG percentage and our budget.