Re: [R] how to change the dataframe labels' ?

From: talepanda <talepanda_at_gmail.com>
Date: Wed 24 Jan 2007 - 11:54:19 GMT

rownames()<- is what you want.

> dat<-data.frame(V1=sample(10),V2=sample(10))
> dat

   V1 V2
1 2 5
2 3 8
3 8 4
4 9 6
5 6 2
6 5 7
7 10 3
8 4 9
9 1 10
10 7 1
> dat<-dat[order(dat$V2),]
> dat

   V1 V2
10 7 1
5 6 2
7 10 3
3 8 4
1 2 5
4 9 6
6 5 7
2 3 8
8 4 9
9 1 10
> rownames(dat)<-1:dim(dat)[1]

## or rownames(dat)<-dat$V2
> dat

   V1 V2
1 7 1
2 6 2
3 10 3
4 8 4
5 2 5
6 9 6
7 5 7
8 3 8
9 4 9
10 1 10

HTH On 1/24/07, domenico pestalozzi <statadat@gmail.com> wrote:
> I import a dataframe composed by 2 variables and 14000 cases. Now I need the
> labels of the cases sorted by the second variable V2, but if I sort the
> dataframe according to the second variable:
>
> mydataframe<- mydataframe[order(mydataframe$V2),]
>
> I notice that the labels are always the same (that is, not ordered by V2).
>
> How to change them?
> I tried :
>
> labels(mydataframe)<-1:14000
>
> but it doesn't work.
>
> Thanks
>
> domenico
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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
> and provide commented, minimal, self-contained, reproducible code.
>



R-help@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 and provide commented, minimal, self-contained, reproducible code. Received on Wed Jan 24 23:02:29 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 24 Jan 2007 - 13:30:34 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.