[R] command to expand a cross classification / contingency table

Greg Snow Greg.Snow at imail.org
Tue Oct 14 05:07:09 CEST 2008


Try:

> mydata2 <- with(mydata, data.frame(Var1 = rep(Var1, Count),
+   Response=rep(Response, Count) )
+ )
> mydata2
  Var1 Response
1    A        1
2    A        2
3    A        2
4    B        6
5    B        6
6    B        6
7    A        7
8    A        7
9    A        7

Hope this helps,
________________________________________
From: r-help-bounces at r-project.org [r-help-bounces at r-project.org] On Behalf Of Juliet Hannah [juliet.hannah at gmail.com]
Sent: Monday, October 13, 2008 8:57 PM
To: r-help at r-project.org
Subject: [R] command to expand a cross classification / contingency table

For data such as

mydata <- read.table(textConnection("Var1 Response Count
A 1 1
A 2 2
B 6 3
A 7 3"),header=TRUE)
closeAllConnections()

is there a command to transform this data so that there is a single
observation per row?

A 1
A 2
A 2
B 6
B 6
B 6
A 7
A 7
A 7

Thanks,

Juliet

______________________________________________
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.



More information about the R-help mailing list