Q:

Formatting output of R

I want to plot the output of R on GNU plot. E.g., I have a matrix x storing integers, and I make matrix y as y<- x^2.
Now GNU plot requires input in input data file in following format:
x1 y1
x2 y2
x3 y3
... and so on...

How can I produce this output file from R?
Specifically, how do I remove indices that are shown in output of R and arrange the elements of a matrix vertically?

A:

It is not entirely clear to me if you want to plot two vectors against each other, or do something with a matrix. I assume the first. Let's create some example data:
x = 1:10
y = x^2    
z = cbind(x, y)

Next, we put this in a file:
write.table(z, file = "/tmp/spam", row.names = FALSE, col.names = FALSE)

and if we check the output:
$ cat /tmp/spam
1 1
2 4
3 9
4 16
5 25
6 36
7 49
8 64
9 81
10 100

I think this is what you need. Alternatively, just do:
plot(y~x, z, type = "l")

and avoid GNUplot altogether. Or even better imo, use ggplot2:
require(ggplot2); theme_set(theme_bw())
qplot(x, y, data = data.frame(z), geom = "line")

A:

There is a basic set of interface functions between R and gnuplot in the TeachingDemos package, see ?gp.open.  These may do what you want, or you can look at the code for an example of creating a datafile in the format that gnuplot wants.

