[R] Make a table

Marc Schwartz MSchwartz at MedAnalytics.com
Wed Dec 22 15:14:28 CET 2004


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




More information about the R-help mailing list