6

I am trying to plot a and b, each consisting of 7500 data points. However when I tried plot(x,y), I got the following error:

> plot(a[11],b[11])
Error in xy.coords(x, y, xlabel, ylabel, log) : 
  (list) object cannot be coerced to type 'double'

Which is strange,because all values all whole numbers. What can I do?

Thank you.

Andrie
  • 176,377
  • 47
  • 447
  • 496
Concerned_Citizen
  • 6,548
  • 18
  • 57
  • 75
  • 4
    this: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Chase Jul 14 '11 at 01:42

1 Answers1

8

It looks like you're trying to plot a vector from a list. Try subseting using $ or [[]] instead.

Here's your problem:

a <- as.list(data.frame("x"=1:5,"y"=5:1))
b <- as.list(data.frame("x"=1:5,"y"=5:1))

plot(a[2],b[2]) ## recreates your error

Here's the solution:

plot(a$y, b$y) ## plots as expected subsetting by $

Alternatively, if you'd prefer to stick with numbers:

plot(a[[2]],b[[2]])

I would strongly recommend that you read the help page associated with this:

?'['
Brandon Bertelsen
  • 43,807
  • 34
  • 160
  • 255