How can I suppress (not print) line numbers?
Code reads:
dd<-data.frame(a=gl(2,3),b=gl(3,1,6) )
model.matrix( ~a + b + a*b, dd )
Tries:
> dd<-data.frame(a=gl(2,3),b=gl(3,1,6) )
> model.matrix( ~a + b + a*b, dd )
(Intercept) a2 b2 b3 a2:b2 a2:b3
1 1 0 0 0 0 0
2 1 0 1 0 0 0
3 1 0 0 1 0 0
4 1 1 0 0 0 0
5 1 1 1 0 1 0
6 1 1 0 1 0 1
attr(,"assign")
[1] 0 1 2 2 3 3
attr(,"contrasts")
attr(,"contrasts")$a
[1] "contr.treatment"
attr(,"contrasts")$b
[1] "contr.treatment"
> cat(model.matrix( ~a + b + a*b, dd ))
1 1 1 1 1 1 0 0 0 1 1 1 0 1 0 0 1 0 0 0 1 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1
> model.matrix( ~ a + b + a*b, dd )
(Intercept) a2 b2 b3 a2:b2 a2:b3
1 1 0 0 0 0 0
2 1 0 1 0 0 0
3 1 0 0 1 0 0
4 1 1 0 0 0 0
5 1 1 1 0 1 0
6 1 1 0 1 0 1
attr(,"assign")
[1] 0 1 2 2 3 3
attr(,"contrasts")
attr(,"contrasts")$a
[1] "contr.treatment"
attr(,"contrasts")$b
[1] "contr.treatment"
> dd<-data.frame(a=gl(2,3),b=gl(3,1,6) )
> print(model.matrix( ~a + b + a*b, dd , rowNames=False))
(Intercept) a2 b2 b3 a2:b2 a2:b3
1 1 0 0 0 0 0
2 1 0 1 0 0 0
3 1 0 0 1 0 0
4 1 1 0 0 0 0
5 1 1 1 0 1 0
6 1 1 0 1 0 1
attr(,"assign")
[1] 0 1 2 2 3 3
attr(,"contrasts")
attr(,"contrasts")$a
[1] "contr.treatment"
attr(,"contrasts")$b
[1] "contr.treatment"
> print(model.matrix( ~a + b + a*b, dd , colNames=False))
(Intercept) a2 b2 b3 a2:b2 a2:b3
1 1 0 0 0 0 0
2 1 0 1 0 0 0
3 1 0 0 1 0 0
4 1 1 0 0 0 0
5 1 1 1 0 1 0
6 1 1 0 1 0 1
attr(,"assign")
[1] 0 1 2 2 3 3
attr(,"contrasts")
attr(,"contrasts")$a
[1] "contr.treatment"
attr(,"contrasts")$b
[1] "contr.treatment"
It is unfortunate that there doesn't seem to be any way to suppress row names when printing matrices, isn't it? One option is to coerce to data.frame and use the row.names
argument of print.data.frame()
:
dd <- data.frame(a=gl(2,3),b=gl(3,1,6));
print(as.data.frame(model.matrix( ~a + b + a*b, dd )),row.names=F);
## (Intercept) a2 b2 b3 a2:b2 a2:b3
## 1 0 0 0 0 0
## 1 0 1 0 0 0
## 1 0 0 1 0 0
## 1 1 0 0 0 0
## 1 1 1 0 1 0
## 1 1 0 1 0 1
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments