Error Using filter condition in Plot statement

Hello All,

I am running below code :

#----install package-----
installed.packages()
install.packages("nycflights13")
library(nycflights13)
nycflights13::flights


#----scatter plot-----
attach(nycflights13::flights)

plot(arr_delay[carrier = "UA"], dep_delay[carrier == "UA"])
points(arr_delay[carrier == "AA"], dep_delay[carrier == "AA"], pch = 4)

But i am getting below error from plot statement:

> plot(arr_delay[carrier = "UA"], dep_delay[carrier == "UA"])
Error in xy.coords(x, y, xlabel, ylabel, log) : 
  'x' and 'y' lengths differ
> points(arr_delay[carrier == "AA"], dep_delay[carrier == "AA"], pch = 4)

On the other hand below plot statement is running just fine without carrier filter condition:

plot(arr_delay, dep_delay,  main = "Arrival vs Departure Delay",
     xlab = "Arrival Delay", ylab = "Departure Delay", pch='p')

Can you point out what am i doing wrong here.

Thank you.

Hi @Shef01,
Welcome to the RStudio Community Forum.
Thanks for posting with an excellent reproducible example!

You code is missing a second "=" character in the first subset of the plot function.
HTH

1 Like

Oh, that was such a silly mistake.
Thank you for pointing out @DavoWW :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.