[R] convert vector to matrix

Gavin Simpson gavin.simpson at ucl.ac.uk
Wed Oct 4 23:19:15 CEST 2006


On Wed, 2006-10-04 at 21:50 +0100, nalluri pratap wrote:
> Hi All,
>    
>    
>   I have vector containing 10 elements(odservations). I need to put
> this into a matrix, where the matrix should contain only one column.
> I need this to be done using the cbind command because in the final
> table I should have a column of attributes( from adifferent vector)
> and a column of vectors from the matrix above
> 
>   Please suggest me how this can be done
>    
>   Thanks and Regards,
>   Pratap

Did you even try to use cbind on your vector? I guess not as,

> vec <- 1:10
> mat <- cbind(vec)
> mat
      vec
 [1,]   1
 [2,]   2
 [3,]   3
 [4,]   4
 [5,]   5
 [6,]   6
 [7,]   7
 [8,]   8
 [9,]   9
[10,]  10
> class(mat)
[1] "matrix"

clearly shows it is possible.

G

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 *Note new Address and Fax and Telephone numbers from 10th April 2006*
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Gavin Simpson                     [t] +44 (0)20 7679 0522
ECRC                              [f] +44 (0)20 7679 0565
UCL Department of Geography
Pearson Building                  [e] gavin.simpsonATNOSPAMucl.ac.uk
Gower Street
London, UK                        [w] http://www.ucl.ac.uk/~ucfagls/cv/
WC1E 6BT                          [w] http://www.ucl.ac.uk/~ucfagls/
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-help mailing list