Plotting in R; cannot be caused by a double error

I am trying to build a and b, each of which consists 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'

This is strange because all values ​​are all integers. What can I do?

Thank.

+5
source share
1 answer

It looks like you are trying to build a vector from a list. Try connecting using $or [[]].

Here is 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 prefer to stick with numbers:

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

I highly recommend you read the help page related to this:

?'['
+7
source

All Articles