0

I have a table with two columns Category,Number and a lot of rows in a CSV file. Each value like 1 in Category has a relation with some values like 1,2,...,k in Number. In other words, my table is:

Category     Number
1            1
1            2
.
.
.
1            100
2            101
2            102
.
.
.
2            200
.
.
.

I want to create itemsets according to the table in CSV file using R, something like this:

1 = (1, 2, ..., 100)
2 = (101, 102, ..., 200)
.
.
.

I googled, but I didn't find any solutions. How can I do this?

Patris
  • 167
  • 2
  • 11
  • Including a [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) in your question will increase your chances of getting an answer. – Samuel Nov 23 '17 at 17:34
  • Look at this question: https://stackoverflow.com/questions/17313450/how-to-convert-data-frame-to-transactions-for-arules – amarchin Nov 23 '17 at 18:09

1 Answers1

1

I'm not sure I understand but maybe one of the two following is what you want.

dat <- data.frame(Category = rep(1:2, each = 100), Number = 1:200)

aggregate(Number ~ Category, dat, list)
aggregate(Number ~ Category, dat, function(x) paste0('(', paste(x, collapse = ", "), ')'))

The first aggregate returns a dataframe where the second column, Number are lists with the elements you call itemsets.
The second aggregate also returns a dataframe, but the second column is of class character, "(1, 2, ..., 100)" and "(101, 102, ..., 200)".

Rui Barradas
  • 70,273
  • 8
  • 34
  • 66