Skip to content
Prev 308085 / 398503 Next

Pivot Table "like" structure

Perhaps this but your results example did not include Char1.
ibrary(reshape2)
md  <-  structure(list(Coutry = structure(c(3L, 3L, 3L, 3L, 2L, 2L, 1L,
1L), .Label = c("J", "M", "U"), class = "factor"), State = structure(c(1L,
1L, 4L, 2L, 5L, 5L, 3L, 6L), .Label = c("A", "C", "K", "O", "S",
"T"), class = "factor"), City = structure(c(1L, 8L, 7L, 2L, 3L,
6L, 5L, 4L), .Label = c("BEN", "HRD", "JKL", "KK", "KL", "KMM",
"OKC", "TYU"), class = "factor"), Char1 = structure(c(1L, 2L,
1L, 3L, 4L, 2L, 3L, 5L), .Label = c("A", "B", "C", "D", "M"), class = "factor"),
    Char2 = structure(c(1L, 2L, 1L, 2L, 3L, 4L, 4L, 2L), .Label = c("ABCD",
    "EFGH", "FGHJ", "GGGG"), class = "factor"), Char3 = structure(c(1L,
    1L, 2L, 3L, 1L, 1L, 2L, 3L), .Label = c("ASDFG", "DDDDD",
    "EEEEEE"), class = "factor")), .Names = c("Coutry", "State",
"City", "Char1", "Char2", "Char3"), row.names = c(NA, -8L), class = "data.frame")

head(md)
str(md)

md1  <-  melt(md, id = c("Coutry", "State", "City"))

apply(md1, 2, count)


John Kane
Kingston ON Canada
____________________________________________________________
GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys
Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and most webmails