Re: [R] eliminating and relabeling the first column

From: jim holtman <jholtman_at_gmail.com>
Date: Sun, 08 Jun 2008 07:09:25 -0400

I am not sure exactly what you were trying to do. read.table will read your data into an object with R and you can change the row names:

> dat <- read.table(textConnection("H1 H2 H3

+ 1 2 3
+ 4 54 6
+ 6 7 8
+ 3 2 1"), header=TRUE)

> closeAllConnections()
> dat

  H1 H2 H3
1 1 2 3
2 4 54 6
3 6 7 8
4 3 2 1
> row.names(dat) <- paste('g', seq(nrow(dat)), sep="")
> dat

   H1 H2 H3
g1 1 2 3
g2 4 54 6
g3 6 7 8
g4 3 2 1
>

It does not change the file on the disk and therefore file.show will display the original file. If you want to rewrite the file, then look at write.table.

On Sun, Jun 8, 2008 at 1:48 AM, Paul Adams <pma3622_at_yahoo.com> wrote:

> Hello everyone,
> I have a data frame in which I am wanting to eliminate the row labels and
> then relabel the rows with
> g1-g2000.I have used the following code:
> dat<-read.table(file="C:\\Documents and Settings\\Owner\\My
> Documents\\colon cancer1.txt",header=T,row.names=1)
> file.show(file="C:\\Documents and Settings\\Owner\\My Documents\\colon
> cancer1.txt")
> I thought that this would eliminate the row labels (first column) because
> of the header=T and row.names=1 argument.
> Then I tried to add the following to relabel the rows (first column)
> g1-g2000
> dat<-read.table(file="C:\\Documents and Settings\\Owner\\My
> Documents\\colon cancer1.txt",header=T,row.names=1)
> row.names(dat)<-paste("g",c(1:nrow(dat)),sep="")
> file.show(file="C:\\Documents and Settings\\Owner\\My Documents\\colon
> cancer1.txt")
> However I still get the same row labels that I have to begin with.
> Any help or explantation would be much appreciated.
> Paul
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

	[[alternative HTML version deleted]]

______________________________________________
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.
Received on Sun 08 Jun 2008 - 11:14:04 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 08 Jun 2008 - 11:30:44 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive