[R] how to "singlify" entries
Petr Pikal
petr.pikal at precheza.cz
Mon May 30 11:48:23 CEST 2005
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 at 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 at precheza.cz
More information about the R-help
mailing list