Published
Edited
Sep 23, 2019
Insert cell
Insert cell
md`

1.data <-Batting%>%
filter(playerID =="ruthba01"| playerID == "mayswi01" | playerID == "bondsba01")%>%
select(playerID,yearID,HR)

write_json(data,"data.json",pretty=TRUE)

install.packages("tidyverse")
> install.packages("Lahman")

> library(jsonlite)
> library(Lahman)
> library(tidyverse)
> data

`
Insert cell
md`2.Master%>%
filter(nameLast == "Sosa")%>%
select(playerID,nameFirst,nameLast)

#mcgwima01 sosasa01 bondsba01

Type in box bellow Master at first to get Master list
`
Insert cell
md`
3.Then delet what you have on the top and put this

data<- Batting%>%
filter(playerID == "mcgwima01"| playerID == "sosasa01" | playerID == "bondsba01")%>%
select(playerID,yearID,HR,H,SO)

write_json(data,"data.json",pretty=TRUE)
`
Insert cell
md`
Practice problem 1 R code. filtered so we got years after 1913

data<- Teams%>%
filter(name == "New York Yankees" | name == "Boston Red Sox")%>%
filter(yearID >= 1913)%>%
select(name,yearID,W)

write_json(data,"data.json",pretty=TRUE)
`
Insert cell
md` Midterm for class.

x<- seq(-4,4,.1)
y<- dnorm(x)
area <- 1-pnorm(x)

data<- tibble (x=x,y=y,area=area)
write_json(data,"data.json",pretty=TRUE)
`
Insert cell
md`second example problem
data<- Salaries%>%
filter(yearID == 2016)%>%
filter(salary>= 15000000)%>%
select (salary)

write_json(data,"data.json",pretty=TRUE)
`
Insert cell
md`
Other problems

x<- seq(-10,10,.1)
data<- tibble (x=x)
write_json(data,"data.json",pretty=TRUE)


>
> write_json(data,"data.json",pretty=TRUE)
>
> x<- seq(-10,10,.1)
> data<- tibble (x=x)
> write_json(data,"data.json",pretty=TRUE)
>
`
Insert cell
md`
Post Midterm, grouping
Batting%>%
filter(playerID== "ruthba01")%>%
group_by(playerID)%>%
summarise(careerHR= sum(HR))
`
Insert cell
md`
Group, mumeraize, generate top 10 list
Batting%>%
group_by(playerID)%>%
summarise(careerHR= sum(HR))%>%
top_n(10)


data<-Batting%>%
group_by(playerID)%>%
summarise(careerHR= sum(HR))%>%
top_n(10)

write_json(data,"data.json",pretty=TRUE)
`
Insert cell
md`
baseball example 2
data<-Batting%>%
filter(playerID=="luzingr01" | playerID== "schmimi01")%>%
select(playerID,HR)


write_json(data,"data.json",pretty=TRUE)


`
Insert cell
md`
hitters<-Batting%>%
filter(yearID<= 1980)%>%
filter(yearID>= 1976)%>%
filter(teamID == "PHI")%>%
group_by(playerID)%>%
summarize(totalHR=sum(HR))%>%
top_n(10)%>%
select(playerID)
then do

allhitters<-Batting%>%
filter(yearID<= 1980)%>%
filter(yearID>= 1976)%>%
filter(teamID == "PHI")%>%
select(playerID,yearID,HR)

allhitters<-Batting%>%
filter(yearID<= 1980)%>%
filter(yearID>= 1976)%>%
filter(teamID == "PHI")%>%
select(playerID,yearID,HR)
inner_join(hitters,allhitters,by=c("playerID"))
`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more