[R] vectorized lines

Mikkel Grum mi2kelgrum at yahoo.com
Sun Aug 8 19:26:04 CEST 2004


Hi,

I thought that the following code would give me a set
of parallel lines on a plot as in the second example.

q<-c(-2253,-2119,-1985,-1850)
p<-c(1,2,3,4)
a<-rep(min(p),4)
b<-rep(max(p),4)
plot(p,q)

# example 1
lines(c(a,b),c(q,q))

Now this gives me the lines I really want:

# example 2
lines(c(a[1],b[1]),c(q[1],q[1]))
lines(c(a[2],b[2]),c(q[2],q[2]))
lines(c(a[3],b[3]),c(q[3],q[3]))
lines(c(a[4],b[4]),c(q[4],q[4]))

I assumed that example 1 was a shorter (vectorized)
way of writing example 2?? What have I got wrong?

cheers,
Mikkel




More information about the R-help mailing list