Dear useR, I have a dataset like this below, > prevRND.dat <- read.table("C:\\workdir\\prevRND.txt", + header=FALSE, # No header. + col.names = c("X","Y","Z"), + sep = ",") > prevRND.dat X Y Z 1 A A 0.950933 2 A B 0.143600 3 A C 0.956133 4 B A 0.000533 5 B B 0.986467 6 B C 0.032066 7 C A 0.005333 8 C B 0.000000 9 C C 0.009266 How can I make that data above as table, Y X A B C A 0.950933 0.143600 0.956133 B 0.000533 0.986467 0.032066 C 0.005333 0.000000 0.009266 I cannot use table() or ftable() functions because the 3rd column (Z) is probability. Are there any function to make a table as I want? Kind regards, Muhammad Subianto
Muhammad, Try tapply(prevRND.dat$Z, list(X=prevRND.dat$X, Y=prevRND.dat$Y), mean) Cheers, Andy __________________________________ Andy Jaworski 518-1-01 Process Laboratory 3M Corporate Research Laboratory ----- E-mail: apjaworski at mmm.com Tel: (651) 733-6092 Fax: (651) 736-3122 Muhammad Subianto <subianto at cs.uu.n l> To Sent by: r-help at stat.math.ethz.ch r-help-bounces at st cc at.math.ethz.ch Subject [R] Make a table 12/22/2004 07:26 AM Dear useR, I have a dataset like this below, > prevRND.dat <- read.table("C:\\workdir\\prevRND.txt", + header=FALSE, # No header. + col.names = c("X","Y","Z"), + sep = ",") > prevRND.dat X Y Z 1 A A 0.950933 2 A B 0.143600 3 A C 0.956133 4 B A 0.000533 5 B B 0.986467 6 B C 0.032066 7 C A 0.005333 8 C B 0.000000 9 C C 0.009266 How can I make that data above as table, Y X A B C A 0.950933 0.143600 0.956133 B 0.000533 0.986467 0.032066 C 0.005333 0.000000 0.009266 I cannot use table() or ftable() functions because the 3rd column (Z) is probability. Are there any function to make a table as I want? Kind regards, Muhammad Subianto ______________________________________________ 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
try: tapply( Z, list( X, Y ), mean ) ---------------------- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 bxc at steno.dk www.biostat.ku.dk/~bxc ----------------------> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of > Muhammad Subianto > Sent: Wednesday, December 22, 2004 2:26 PM > To: r-help at stat.math.ethz.ch > Subject: [R] Make a table > > > Dear useR, > > I have a dataset like this below, > > prevRND.dat <- read.table("C:\\workdir\\prevRND.txt", > + header=FALSE, # No header. > + col.names = c("X","Y","Z"), > + sep = ",") > > prevRND.dat > X Y Z > 1 A A 0.950933 > 2 A B 0.143600 > 3 A C 0.956133 > 4 B A 0.000533 > 5 B B 0.986467 > 6 B C 0.032066 > 7 C A 0.005333 > 8 C B 0.000000 > 9 C C 0.009266 > > How can I make that data above as table, > > Y > X A B C > A 0.950933 0.143600 0.956133 > B 0.000533 0.986467 0.032066 > C 0.005333 0.000000 0.009266 > > I cannot use table() or ftable() functions because the 3rd > column (Z) is > probability. Are there any function to make a table as I want? > > Kind regards, > Muhammad Subianto > > ______________________________________________ > 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 >
On Wed, 2004-12-22 at 14:26 +0100, Muhammad Subianto wrote:> Dear useR, > > I have a dataset like this below, > > prevRND.dat <- read.table("C:\\workdir\\prevRND.txt", > + header=FALSE, # No header. > + col.names = c("X","Y","Z"), > + sep = ",") > > prevRND.dat > X Y Z > 1 A A 0.950933 > 2 A B 0.143600 > 3 A C 0.956133 > 4 B A 0.000533 > 5 B B 0.986467 > 6 B C 0.032066 > 7 C A 0.005333 > 8 C B 0.000000 > 9 C C 0.009266 > > How can I make that data above as table, > > Y > X A B C > A 0.950933 0.143600 0.956133 > B 0.000533 0.986467 0.032066 > C 0.005333 0.000000 0.009266 > > I cannot use table() or ftable() functions because the 3rd column (Z) is > probability. Are there any function to make a table as I want?How about:> xtabs(Z ~ X + Y, data = prevRND.dat)Y X A B C A 0.950933 0.143600 0.956133 B 0.000533 0.986467 0.032066 C 0.005333 0.000000 0.009266 HTH, Marc Schwartz
Thanks to all of you. That's what I want. Best wishes, Muhammad Subianto Try tapply(prevRND.dat$Z, list(X=prevRND.dat$X, Y=prevRND.dat$Y), mean) __________________________________ Andy Jaworskitry: try: tapply( Z, list( X, Y ), mean ) ---------------------- Bendix Carstensen How about:>> xtabs(Z ~ X + Y, data = prevRND.dat) > >Y X A B C A 0.950933 0.143600 0.956133 B 0.000533 0.986467 0.032066 C 0.005333 0.000000 0.009266 HTH, Marc Schwartz