开发者

Plotting in R; cannot be coerced to double error

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 'doubl开发者_StackOverflowe'

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

Thank you.


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:

?'['
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜