# Strange behaviour with Cbind

#### leejayd

##### New Member
Hi,

I'm trying to reshape data and as part of this I have a data object containing a data frame that can have multiple pairs of XY columns and around 400 rows of numbers. I need to run a function for each pair of XY columns.

Eventually I'm looking to loop through the frame and extract each pair into a matrix.

Here's my question :

The statement below gives me a matrix but it's no good referring to the file with names as I won't know of these in advance.

xy <-cbind(data$PageViews.2014, data$Conversions.2014)

In readiness for the looping I'm trying to refer to the columns by column number :

xy <-cbind(data[1], data[2])

This statement gives me a Data Frame rather than an n*p matrix.

I ultimately need the pairs of XY columns in a n*p matrix. What's the best way of doing this? I'd rather do it in one stop per XY columns if possible.

Any suggestions would be gratefully received.

#### trinker

##### ggplot2orBust
Try:

Code:
xy <-cbind(data[, 1], data[, 2])

#### leejayd

##### New Member
That works perfectly. I didn't realise we could refer to frames like this. Thanks so much.