[R] Suppressing observation numbers
Prof Brian Ripley
ripley at stats.ox.ac.uk
Wed Mar 2 23:34:46 CET 2005
On Thu, 3 Mar 2005, Nam-Ky Nguyen wrote:
> Dear R gurus,
>
> Below is a part of the R output. Please consider the two lines:
>> data
>> model.matrix(m1)
>
> Is there a way of suppressing the observation numbers 1, 2, ...27 in the
> output (I don't want these number to appear in the output)?
Actually, these are the row names of a data frame, and the answer is yes.
(Note: I _have_ answered your question!)
If you meant to ask how to do it, here is a hint
library(MASS); write.matrix(hills)
>
> Regards,
> NKN
>
>> # Orthogonal blocking
>> data=read.table("cut.txt",header=T)
>> attach(data)
>> data
> b x1 x2 x3
> 1 1 -1 -1 0
> 2 1 -1 0 1
> 3 1 -1 1 -1
> 4 1 0 -1 0
> 5 1 0 0 1
> 6 1 0 1 -1
> 7 1 1 -1 -1
> 8 1 1 0 0
> 9 1 1 1 1
> 10 2 -1 -1 -1
> 11 2 -1 0 0
> 12 2 -1 1 1
> 13 2 0 -1 1
> 14 2 0 0 -1
> 15 2 0 1 0
> 16 2 1 -1 0
> 17 2 1 0 1
> 18 2 1 1 -1
> 19 3 -1 -1 1
> 20 3 -1 0 -1
> 21 3 -1 1 0
> 22 3 0 -1 -1
> 23 3 0 0 0
> 24 3 0 1 1
> 25 3 1 -1 1
> 26 3 1 0 -1
> 27 3 1 1 0
>> b=factor(b)
>> y=rnorm(27)
>> x4=x1*x2
>> x5=x1*x3
>> x6=x2*x3
>> x7=x1*x1
>> x8=x2*x2
>> x9=x3*x3
>> options(contrasts=c("contr.sum","contr.poly"))
>> m1=lm(y~b+x1+x2+x3+x4+x5+x6+x7+x8+x9)
>> model.matrix(m1)
> (Intercept) b1 b2 x1 x2 x3 x4 x5 x6 x7 x8 x9
> 1 1 1 0 -1 -1 0 1 0 0 1 1 0
> 2 1 1 0 -1 0 1 0 -1 0 1 0 1
> 3 1 1 0 -1 1 -1 -1 1 -1 1 1 1
> 4 1 1 0 0 -1 0 0 0 0 0 1 0
> 5 1 1 0 0 0 1 0 0 0 0 0 1
> 6 1 1 0 0 1 -1 0 0 -1 0 1 1
> 7 1 1 0 1 -1 -1 -1 -1 1 1 1 1
> 8 1 1 0 1 0 0 0 0 0 1 0 0
> 9 1 1 0 1 1 1 1 1 1 1 1 1
> 10 1 0 1 -1 -1 -1 1 1 1 1 1 1
> 11 1 0 1 -1 0 0 0 0 0 1 0 0
> 12 1 0 1 -1 1 1 -1 -1 1 1 1 1
> 13 1 0 1 0 -1 1 0 0 -1 0 1 1
> 14 1 0 1 0 0 -1 0 0 0 0 0 1
> 15 1 0 1 0 1 0 0 0 0 0 1 0
> 16 1 0 1 1 -1 0 -1 0 0 1 1 0
> 17 1 0 1 1 0 1 0 1 0 1 0 1
> 18 1 0 1 1 1 -1 1 -1 -1 1 1 1
> 19 1 -1 -1 -1 -1 1 1 -1 -1 1 1 1
> 20 1 -1 -1 -1 0 -1 0 1 0 1 0 1
> 21 1 -1 -1 -1 1 0 -1 0 0 1 1 0
> 22 1 -1 -1 0 -1 -1 0 0 1 0 1 1
> 23 1 -1 -1 0 0 0 0 0 0 0 0 0
> 24 1 -1 -1 0 1 1 0 0 1 0 1 1
> 25 1 -1 -1 1 -1 1 -1 1 -1 1 1 1
> 26 1 -1 -1 1 0 -1 0 -1 0 1 0 1
> 27 1 -1 -1 1 1 0 1 0 0 1 1 0
> attr(,"assign")
> [1] 0 1 1 2 3 4 5 6 7 8 9 10
> attr(,"contrasts")
> attr(,"contrasts")$b
> [1] "contr.sum"
>
>
>
> --
> Nam-Ky Nguyen, Senior Lecturer
> School of Mathematics, Statistics and Computer Science
> University of New England, Armidale NSW 2351 Australia
> nkn at turing.une.edu.au Tel: +612 6773 2763
> http://turing.une.edu.au/~nkn Fax: +612 6773 3312
>
> Please convert Word files to PDF files before sending them to me.
> See http://www.gnu.org/philosophy/no-word-attachments.html
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list