Re: [R] how to "singlify" entries

From: Petr Pikal <petr.pikal_at_precheza.cz>
Date: Mon 30 May 2005 - 19:48:23 EST


Hallo

On 30 May 2005 at 9:15, zhihua li wrote:

> hi netters
>
> I have a rather simple question. I have a data frame with two

Well, I do not understand you simple question fully. You have something like that

dat<-data.frame(X=1:100, Y=sample(1:10,10))

dat$X<-factor(dat$X)
dat$Y<-factor(dat$Y)
dat$Y[5]<-10

> variables X and Y, both of which are factors. X has 100 levels while Y
> has 10 levels only. The data frame has 100 rows in all, so for X the
> values are unique, and Y has many replicate values. Now I wanna
> reduce the data frame into 10 rows only, according to the 10 levels of
> Y. I don't care which value of X is in the same row with Y in the
> final data frame, as long as it is in agreement with the original data
> frame.

Do you want to choose only some rows from your data frame to get unique Y and any corresponding X?

dat[!duplicated(dat$Y),]

Or do you want something different?

HTH
Petr

>
> I think this task can be carried out with some function like
> aggregate. but I failed in figuring it out. Could anybody give me a
> hint?
>
> Thanks a lot!
>
> ______________________________________________
> 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

Petr Pikal
petr.pikal@precheza.cz



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 Received on Mon May 30 19:55:15 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:15 EST