I could not find any previous questions posted on this, so perhaps you can help.

What is a good way to aggregate data in a tm corpus based on metadata (e.g. aggregate texts of different writers)?

There are at least two obvious ways it could be done:

* A built-in function in tm, that would allow a DocumentTermMatrix to be built on a metadata feature. Unfortunately I haven't been able to uncover this.
* A way to join documents within a corpus based on some external metadata in a table. It would just use metadata to replace document-ids.

So you would have a table that contains: DocumentId, AuthorName

And a tm-built corpus that contains an amount of documents. I understand it is not difficult to introduce the table as metadata for the corpus object. 

A matrix can be built with a following function. 

```
library(tm) # version 0.6, you seem to be using an older version
corpus  <-Corpus(DirSource("/directory-with-texts"),
 readerControl = list(language="lat"))

metadata <- data.frame(DocID, Author)

#A very crude way to enter metadata into the corpus (assumes the same sequence):
for (i in 1:length(corpus)) {
  attr(corpus[[i]], "Author") <- metadata$Author[i]
}

a_documenttermmatrix_by_DocId <-DocumentTermMatrix(corpus) 

```

How would you build a matrix that shows frequencies for each author possibly aggregating multiple documents instead of documents? It would be useful to do this just at this stage and not in post-processing with only a few terms.

```
a_documenttermmatrix_by_Author <- ?

```

Many thanks!