0

Here's the sample data:

a <- structure(list(Occ = c(1, 2, 3, 4, 4, 5, 6, 4, 8, 5), 
Type = c("A", "B", "C", "A", "A", "A", "B", "C", "C", "B"), 
Alc = c("A", "B", "N", "A", "N", "N", "N", "A", "B", "B"), 
Count = c(10, 10, 20, 10, 15, 15, 10, 10, 20, 15)),
.Names = c("Occ", "Type", "Alc", "Count"), row.names = c(NA, -10L), class = "data.frame")

I like to get the frequency count of each attribute of the columns like the following:

Occ:    Type    Alc     Count
1: 1    A: 4    A: 3    10: 5
2: 1    B: 3    B: 3    15: 3   
3: 1    C: 3    N: 4    20: 2
4: 3
5: 2
6: 1
8: 1

This problem can be solved partially by 'summary' function in 'anacor' package. I am still looking for a better solution.

S Das
  • 3,291
  • 6
  • 26
  • 41
  • 3
    This question appears to be off-topic because it is *not* about programming – Gavin Simpson Jun 28 '13 at 03:26
  • I like to rephrase it into a programming question. A dataset contains both numerical and categorical data. I like to get the attribute count of the dataset. – S Das Jun 28 '13 at 03:32
  • Do read the [ask] section of the [faq] plus the [How to make a reproducible example](http://stackoverflow.com/q/5963269/429846) question for details on how to write great, useful Questions. We need some idea of how the data looks, plus expected output. – Gavin Simpson Jun 28 '13 at 03:40
  • @GavinSimpson, The previous question is edited. – S Das Jul 01 '13 at 05:27
  • 1
    Does this suffice? `lapply(a, table)`? I can't add this as an Answer until your Q is reopened so I will eave it here. – Gavin Simpson Jul 01 '13 at 05:39

2 Answers2

3

Actually summary.default does something like that. The answer will depend on whether you mean real R "attributes" or just some vague natural language understanding of attributes. str is the way to look at everything about an object. There are also several versions of describe. The one I use is Hmisc::describe but some of the other packages have different versions. (I wish there were a way to insist that a particular function NOT be masked by the latest package's version.)

IRTFM
  • 258,963
  • 21
  • 364
  • 487
1

I would probably use table on the elements of a, as in

> lapply(a, table)
$Occ

1 2 3 4 5 6 8 
1 1 1 3 2 1 1 

$Type

A B C 
4 3 3 

$Alc

A B N 
3 3 4 

$Count

10 15 20 
 5  3  2 
Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453