I want to build a 3x3 data.frame in R by using two vectors of values: a vector of x-values (xr) and a vector of y-values (yr). xr has 3 values and yr has 9 values.
Here my example:
xr<-c(1,2,3)
yr<-c(4,4,4,5,5,5,6,6,6)
db<-data.frame(x=xr,y=yr)
The resulting data.frame is as follows:
> db
x y
1 4
2 4
3 4
1 5
2 5
3 5
1 6
2 6
3 6
However, I would like the data.frame to be like this:
> db
x y
1 4
1 4
1 4
2 5
2 5
2 5
3 6
3 6
3 6
The trivial way to do it would be to use another xr, with the explicit sequence of values of x, like this:
xr<-c(1,2,3,1,2,3,1,2,3)
However I am looking for a way of creating such data.frame by using the same xr as in my first example.
Any help is much appreciated!