Re: [R] Are you sure a table can become a data.frame?

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sun, 16 Nov 2008 14:46:29 -0500

Try:

as.data.frame.matrix(table(X))

On Sun, Nov 16, 2008 at 1:28 PM, CE.KA <ce.kaya75_at_yahoo.fr> wrote:
>
> Hi R users,
>
> Imagine X as a data frame:
>
> X=read.table(textConnection("
> Var1 Var2
> 1 A H
> 2 B K
> 3 A H
> 4 B H
> 5 C L
> "),header=TRUE)
> closeAllConnections()
>
> X X is a data frame
> Var1 Var2
> 1 A H
> 2 B K
> 3 A H
> 4 B H
> 5 C L
>
> Y<-table(X$Var1,X$Var2) Y is a cross table between Var1 and Var2
> I want Y to become a data
> frame
>
> Y
> H K L
> A 2 0 0
> B 1 1 0
> C 0 0 1
>
> Z<-as.data.frame(Y) I want Y to become a data frame: it
> doesn't work
> Z
> Var1 Var2 Freq
> 1 A H 2
> 2 B H 1
> 3 C H 0
> 4 A K 0
> 5 B K 1
> 6 C K 0
> 7 A L 0
> 8 B L 0
> 9 C L 1
>
> I expect Z as following data frame
> Z
> H K L
> A 2 0 0
> B 1 1 0
> C 0 0 1
>
> I tried as.data.frame(array(x, dim(x), dimnames(x))) and
> as.data.frame.table
> but it doesn'work
> Kind regards
>
> --
> View this message in context: http://www.nabble.com/Are-you-sure-a-table-can-become-a-data.frame--tp20528308p20528308.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 16 Nov 2008 - 19:50:01 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 16 Nov 2008 - 20:30:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive