[R] Changing Matrix Header

Simon Pickett simon.pickett at bto.org
Tue Jan 6 10:39:11 CET 2009


Hi Gundala,

try chopping off the top row like
newx<-as.matrix(x[2:dim(x)[1],])

OR

try changing it to a data frame...
new x<-data.frame(x,row.names=NULL)

#pretty sure its not row.names but there is probably an equivalent for 
col.names

OR

look into ?read.table and specify header = F

Cheers, Si.





----- Original Message ----- 
From: "Gundala Viswanath" <gundalav at gmail.com>
To: <r-help at stat.math.ethz.ch>
Sent: Tuesday, January 06, 2009 8:14 AM
Subject: [R] Changing Matrix Header


> Dear all,
>
> I have the following matrix.
>
>> dat
>         A A A A A A A A A A
>    [1,] 0 0 0 0 0 0 0 0 0 0
>    [2,] 0 0 0 0 0 0 0 0 0 1
>    [3,] 0 0 0 0 0 0 0 0 0 2
>
> How can I change it into:
>         [,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7]  [,8]   [,9]   [,10]
>    [1,] 0     0     0      0     0     0     0     0     0       0
>    [2,] 0     0     0      0     0     0     0     0     0       1
>    [3,] 0     0     0      0     0     0     0     0     0        2
>
>
> I tried:
>
>> as.matrix(x)
>
> But failed.
>
>
> - Gundala Viswanath
> Jakarta - Indonesia
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>




More information about the R-help mailing list