hi netters I have a rather simple question. I have a data frame with two 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. 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!
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 twoWell, 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.htmlPetr Pikal petr.pikal at precheza.cz
On Mon, May 30, 2005 at 09:15:32AM +0000, zhihua li wrote :> hi netters > > I have a rather simple question. I have a data frame with two 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.Dear list, I am a new subscriber, using R to analyse genomics data. I have a similar question, maybe even identical, but I am not sure...>From a data frame with two factors and one value, I would like to obtain a dataframe with one factor and one value per level in the removed factor. For instance: F1 F2 V ----------------- A X 3 A Y 6 B X 5 C X 9 C Y 3 Would become: F1 VX VY ------------------ A 3 6 B 5 0 C 9 3 I am sure I have seen a tool to do this some time ago, but I do not remember its name. Can somebody help me ? Best regards, -- Charles Plessy, Ph.D. - Genome Science Laboratory The Institute for Physical and Chemical Research (RIKEN) 2-1 Hirosawa, Wako, Saitama 351-0198, Japan plessy at riken.jp -- Fax: 048-462-4686 -- Tel: 048-467-9515
On 30 May 2005 at 21:56, Charles Plessy wrote:> On Mon, May 30, 2005 at 09:15:32AM +0000, zhihua li wrote : > > hi netters > > > > I have a rather simple question. I have a data frame with two > > 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. > > Dear list, > > I am a new subscriber, using R to analyse genomics data. I have a > similar question, maybe even identical, but I am not sure...Hallo Me neither. ?reshape> dat<-read.table("clipboard", header=T) > datF1 F2 V 1 A X 3 2 A Y 6 3 B X 5 4 C X 9 5 C Y 3> reshape(dat, idvar="F1", timevar="F2",direction="wide")F1 V.X V.Y 1 A 3 6 3 B 5 NA 4 C 9 3 Homework: change NA to zero. HTH Petr> > >From a data frame with two factors and one value, I would like to > >obtain a data > frame with one factor and one value per level in the removed factor. > > For instance: > > F1 F2 V > ----------------- > A X 3 > A Y 6 > B X 5 > C X 9 > C Y 3 > > Would become: > > F1 VX VY > ------------------ > A 3 6 > B 5 0 > C 9 3 > > I am sure I have seen a tool to do this some time ago, but I do not > remember its name. > > Can somebody help me ? > > Best regards, > > -- > Charles Plessy, Ph.D. - Genome Science Laboratory > The Institute for Physical and Chemical Research (RIKEN) > 2-1 Hirosawa, Wako, Saitama 351-0198, Japan > plessy at riken.jp -- Fax: 048-462-4686 -- Tel: 048-467-9515 > > ______________________________________________ > 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.htmlPetr Pikal petr.pikal at precheza.cz