DS4PS / cpp-526-spr-2020

Course shell for CPP 526 Foundations of Data Science I for Spring 2020.
http://ds4ps.org/cpp-526-spr-2020/
3 stars 0 forks source link

Lab 3 - Error returned after year index and plotting #16

Closed JasonSills closed 4 years ago

JasonSills commented 4 years ago

Hi, I'm trying to recreate my graph with the instructions in last night's video. However, after I index the years the plot is returning an error that my x and y are not the same length. Where am I going wrong? Code for indexing the year:

ave.so <- Teams$SO / Teams$G
year <- (Teams$yearID )

# min and max values needed to create your plot window 
ave.so.min <- min( ave.so, na.rm=T )
ave.so.max <- max( ave.so, na.rm=T )

# the league average for each season
league.ave <- tapply( X=ave.so, INDEX=as.factor(year), FUN="mean", na.rm=T )
league.year <- as.numeric( names( league.ave ) )

# Truncate years to >=1900 & <=2012

index <- which(year >=1900 & year <=2012)
year <- year[index]
ave.so < ave.so[index]

index2 <-which(league.year >=1900 & league.year <=2012)

league.year <- league.year[index2]
league.ave <- league.ave[index2]

Code for plots: plot.new() plot.window(xlim=c(1900, 1980), ylim=c(ave.so.min, ave.so.max)) points( year, ave.so )

error: Error in xy.coords(x, y) : 'x' and 'y' lengths differ

JasonSills commented 4 years ago

Never mind. A line was missing. Found it.

jamisoncrawford commented 4 years ago

Sorry, just read this - glad you figured it out! Watch out for the "gotchya" in the xlim = argument in your call to plot.window()!