Hi, I have a data set look like this: ================================Fruit Quty apple 20 banana 10 orange 17 apple 30 apple 15 orange 26 banana 15 .........and so on .......... ================================ The level of fruit is 30, that is, there are 30 different fruits. I'd like to compute some simple statistics for each different fruit and get output like this: ================================ min max avg median apple 12 70 25 22 banana 10 65 19 18 orange 19 50 27 25 ....... and so on........ ================================ Please help me with this. Thanks, Yu-Ling Wu __________________________________________________ Do You Yahoo!? Yahoo! Auctions - Buy the things you want at great prices. http://auctions.yahoo.com/ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Thanks, it's helpful. I'm wondering how to make the output look better. Right now, I got the output look like this: ======================================$"apple" Fruit Quty apple : 72 Min. : 12.00 banana : 0 1st Qu.: 14.00 orange : 0 Median : 22.00 cherry : 0 Mean : 25.00 mengo : 0 3rd Qu.: 42.00 pineapple : 0 Max. : 70.00 (Other) : 0 $"banana" Fruit Quty banana : 37 Min. : 10.00 apple : 0 1st Qu.: 13.00 orange : 0 Median : 18.00 cherry : 0 Mean : 19.00 mengo : 0 3rd Qu.: 32.00 pineapple : 0 Max. : 65.00 (Other) : 0 ......and so on........ ====================================== How to make it look like below and dilimited by Tab? ====================================== min max avg median count apple 12 70 25 22 72 banana 10 65 19 18 37 orange 19 50 27 25 52 ....... and so on........ ====================================== --- "Richards, Tom" <richards at pci.upmc.edu> wrote:> You can try: > > lapply(split(dset,dset$fruit,summary)) > > Tom Richards > > > -----Original Message----- > > From: Yu-Ling Wu [mailto:yuling5 at yahoo.com] > > Sent: Wednesday, March 14, 2001 6:11 PM > > To: R-Help > > Subject: [R] get statistics by group > > > > > > Hi, > > > > I have a data set look like this: > > > > ================================> > Fruit Quty > > apple 20 > > banana 10 > > orange 17 > > apple 30 > > apple 15 > > orange 26 > > banana 15 > > .........and so on .......... > > ================================> > > > The level of fruit is 30, that is, there are 30 > > different fruits. I'd like to compute some simple > > statistics for each different fruit and get output > > > like this: > > > > ================================> > min max avg median > > apple 12 70 25 22 > > banana 10 65 19 18 > > orange 19 50 27 25 > > ....... and so on........ > > ================================> > > > Please help me with this. > > > > Thanks, > > Yu-Ling Wu__________________________________________________ Do You Yahoo!? Yahoo! Auctions - Buy the things you want at great prices. http://auctions.yahoo.com/ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 14 Mar 2001, Yu-Ling Wu wrote:> Thanks, it's helpful. > I'm wondering how to make the output look better. > Right now, I got the output look like this: > > ======================================> $"apple" > Fruit Quty > apple : 72 Min. : 12.00 > banana : 0 1st Qu.: 14.00 > orange : 0 Median : 22.00 > cherry : 0 Mean : 25.00 > mengo : 0 3rd Qu.: 42.00 > pineapple : 0 Max. : 70.00 > (Other) : 0 > > > $"banana" > Fruit Quty > banana : 37 Min. : 10.00 > apple : 0 1st Qu.: 13.00 > orange : 0 Median : 18.00 > cherry : 0 Mean : 19.00 > mengo : 0 3rd Qu.: 32.00 > pineapple : 0 Max. : 65.00 > (Other) : 0 > > ......and so on........ > > ======================================> > > How to make it look like below and dilimited by Tab? > > > ======================================> min max avg median count > apple 12 70 25 22 72 > banana 10 65 19 18 37 > orange 19 50 27 25 52 > > ....... and so on........ > > ======================================You are aiming pretty high for a newbie!Do you expect to be able to reformat the output of canned stats programs like SPSS or SAS? The short answer is that it is a lot of work to get R to put the results in the format you want. Bill -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Yu-Ling Wu <yuling5 at yahoo.com> writes:>Hi, > >I have a data set look like this: > >================================>Fruit Quty >apple 20 >banana 10 >orange 17 >apple 30 >apple 15 >orange 26 >banana 15 >.........and so on .......... >================================> >The level of fruit is 30, that is, there are 30 >different fruits. I'd like to compute some simple >statistics for each different fruit and get output >like this: > >================================> min max avg median >apple 12 70 25 22 >banana 10 65 19 18 >orange 19 50 27 25 >....... and so on........ >================================> >Please help me with this. >Try: by(Quty, Fruit, summary) Mark -- Mark Myatt -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._