I have simple data frame containing short strings, each which has a particular class assigned:

```
datadb <- data.frame (
  Class = c('Class1', 'Class2', 'Class3'),
  Document = c('This is test', 'Yet another test', 'A last test')
)

datadb$Document <- tolower(datadb$Document)
datadb$Tokens   <- strsplit(datadb$Document, " ")

```

From this, I want to build another data frame which contains the original `Class1` column, but which has a new column added for each unique token, something like this:

```
all_tokens <- unlist(datadb$Tokens)
all_tokens <- unique(all_tokens)

number_of_columns <- length(all_tokens)
number_of_rows    <- NROW(datadb)

tokenDB <- data.frame( matrix(ncol=(1 + number_of_columns), nrow=number_of_rows) )

names(tokenDB) <- c("Classification", all_tokens)
tokenDB$Classification <- datadb$Class

```

The `tokenDB` will then look like this:

```
Classification this is test yet another  a last
1         Class1   NA NA   NA  NA      NA NA   NA
2         Class2   NA NA   NA  NA      NA NA   NA
3         Class3   NA NA   NA  NA      NA NA   NA

```

How can I go through the original data frame and add a value to the new `tokenDB` corresponding to each of the vectors already identified? The output should look like:

```
Classification    this   is   test   yet   another  a last
1         Class1    1    1     1     0       0      0   0
2         Class2    0    0     1     1       1      0   0
3         Class3    0    0     1     0       0      1   1

```

The output should ideally be a data.frame, but could also be a matrix.