Re: [R] matrix in data.frame

From: Lina Hultin-Rosenberg <>
Date: Wed, 30 May 2007 12:58:24 +0200

Thank you so much for your help, it worked of course!

Best regards,

Lina Hultin-Rosenberg

-----Ursprungligt meddelande-----
Från: Prof Brian Ripley [] Skickat: den 30 maj 2007 12:44
Till: Lina Hultin-Rosenberg
Ämne: Re: [R] matrix in data.frame

You need to use I() or something similar. E.g.

A <- matrix(1:6, 2,3)
data.frame(x=1:2, I(A))

X <- data.frame(x=1:2)
X$A <- A

both insert A as a single column.

On Wed, 30 May 2007, Lina Hultin-Rosenberg wrote:

> Dear list!
> I have run into a problem that seems very simple but I can't find any
> solution to it (have searched the internet, help-files and "An
> to R" etc without any luck). The problem is the following: I would like to
> create a data.frame with two components (columns), the first component
> a matrix and the second component a vector. Whatever I have tried so far,
> end up with a data.frame containing all the columns from the matrix plus
> vector which is not what I am after. I have seen this kind of data.frame
> among R example datasets (oliveoil and yarn).
> I would greatly appreciate some help with this problem!
> Kind regards,
> Lina Hultin Rosenberg
> Karolinska Biomics Center
> Karolinska Institute
> Sweden

Brian D. Ripley,        
Professor of Applied Statistics,
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Wed 30 May 2007 - 11:03:11 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 30 May 2007 - 11:31:34 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.