[R] Removing "row.names"

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Feb 7 12:26:02 CET 2001


> Date: Wed, 7 Feb 2001 11:05:05 +0000 (GMT)
> From: Dermot MacSweeney <dsweeney at nmrc.ucc.ie>
> Subject: Re: [R] Removing "row.names"
> To: r-help at stat.math.ethz.ch
> X-Virus-Scanned: by AMaViS at NMRC, Ireland
> 
> If a data.frame formed as follows:
> 
> sampled <- data.frame(sample(rnorm(100),2))
> 
> sampled
>  
> The output is:
> 
>   sample.rnorm.100...2.
> 1            -0.1124964
> 2            -1.4590381
> 
> What I would like to have is no column titles so I get this:
> 
> 1            -0.1124964
> 2            -1.4590381
> 
> I don't have a lot of experience with R, so excuse me if this is a stupid 
> question.

Certainly not, but there are two separate things going on you
need to keep separate.

1) A data frame has row names and column names.
You have sensible row names.
You can get better column names by

sampled <- data.frame(x = sample(rnorm(100),2))

or afterwards by

names(sampled) <- "x".

2) By default, a data frame is printed with row and column names.
You can change that.  The simplest way is probably (for 1.2.1)

zz <- as.matrix(format(sampled))
colnames(zz) <- rep("", ncol(zz))
print(zz, quote=FALSE)

or use

myprint <- function(df)
{
    zz <- as.matrix(format(df))
    colnames(zz) <- rep("", ncol(zz))
    print(zz, quote=FALSE)
    invisible(df) 
}
> myprint(sampled)
             
1 -0.76797637
2  0.08913408



-- 
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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list