R package arules: read.transactions file format

Multi tool use
I have a .csv file with the following type of data:
Day Item
1 12,19,24,31,48,
1 1,19,
1 16,28,32,45,
1 19,36,41,43,44,
1 7,24,27,
1 21,31,33,41,
1 46
1 50
2 12,31,36,48,
2 17,29,47,
2 2,18,20,29,38,39,40,41
2 17,29,47,
And I can't get the read.transactions to read it properly.
The data set is based on several item selection for each day (more than one time per day, if necessary). For instance, the third selection on day 1, returned items 16,28,32, and 45.
Shouldn't this be enough?
library(arules)
dataset <- read.transactions("file.csv", format = 'basket')
r arules
|
show 5 more comments
I have a .csv file with the following type of data:
Day Item
1 12,19,24,31,48,
1 1,19,
1 16,28,32,45,
1 19,36,41,43,44,
1 7,24,27,
1 21,31,33,41,
1 46
1 50
2 12,31,36,48,
2 17,29,47,
2 2,18,20,29,38,39,40,41
2 17,29,47,
And I can't get the read.transactions to read it properly.
The data set is based on several item selection for each day (more than one time per day, if necessary). For instance, the third selection on day 1, returned items 16,28,32, and 45.
Shouldn't this be enough?
library(arules)
dataset <- read.transactions("file.csv", format = 'basket')
r arules
I think you need to specify thesep
– akrun
Dec 30 '18 at 20:38
What happens when you try the code? An error? What error?
– IceCreamToucan
Dec 30 '18 at 20:38
@akrun, thanks for your comment. However, I already tried to specifysep=","
or even revome the commas from the CSV but the dataset analysis isn't done properly
– Paulos
Dec 30 '18 at 20:39
1
You have a quote missing inbasket
. If i doread.transactions("file.csv", format = 'basket', sep=",")# transactions in sparse format with 13 transactions (rows) and 32 items (columns)
– akrun
Dec 30 '18 at 20:40
@IceCreamToucan the dataset isn't analyzed properly. For instance, it is saying that all rows have only 2 elements (it must be using only the first two numbers). Instead, it should be detecting the first as a class and the following (separeted by commas), as the elements.
– Paulos
Dec 30 '18 at 20:41
|
show 5 more comments
I have a .csv file with the following type of data:
Day Item
1 12,19,24,31,48,
1 1,19,
1 16,28,32,45,
1 19,36,41,43,44,
1 7,24,27,
1 21,31,33,41,
1 46
1 50
2 12,31,36,48,
2 17,29,47,
2 2,18,20,29,38,39,40,41
2 17,29,47,
And I can't get the read.transactions to read it properly.
The data set is based on several item selection for each day (more than one time per day, if necessary). For instance, the third selection on day 1, returned items 16,28,32, and 45.
Shouldn't this be enough?
library(arules)
dataset <- read.transactions("file.csv", format = 'basket')
r arules
I have a .csv file with the following type of data:
Day Item
1 12,19,24,31,48,
1 1,19,
1 16,28,32,45,
1 19,36,41,43,44,
1 7,24,27,
1 21,31,33,41,
1 46
1 50
2 12,31,36,48,
2 17,29,47,
2 2,18,20,29,38,39,40,41
2 17,29,47,
And I can't get the read.transactions to read it properly.
The data set is based on several item selection for each day (more than one time per day, if necessary). For instance, the third selection on day 1, returned items 16,28,32, and 45.
Shouldn't this be enough?
library(arules)
dataset <- read.transactions("file.csv", format = 'basket')
r arules
r arules
edited Dec 30 '18 at 20:47
Paulos
asked Dec 30 '18 at 20:34


PaulosPaulos
235
235
I think you need to specify thesep
– akrun
Dec 30 '18 at 20:38
What happens when you try the code? An error? What error?
– IceCreamToucan
Dec 30 '18 at 20:38
@akrun, thanks for your comment. However, I already tried to specifysep=","
or even revome the commas from the CSV but the dataset analysis isn't done properly
– Paulos
Dec 30 '18 at 20:39
1
You have a quote missing inbasket
. If i doread.transactions("file.csv", format = 'basket', sep=",")# transactions in sparse format with 13 transactions (rows) and 32 items (columns)
– akrun
Dec 30 '18 at 20:40
@IceCreamToucan the dataset isn't analyzed properly. For instance, it is saying that all rows have only 2 elements (it must be using only the first two numbers). Instead, it should be detecting the first as a class and the following (separeted by commas), as the elements.
– Paulos
Dec 30 '18 at 20:41
|
show 5 more comments
I think you need to specify thesep
– akrun
Dec 30 '18 at 20:38
What happens when you try the code? An error? What error?
– IceCreamToucan
Dec 30 '18 at 20:38
@akrun, thanks for your comment. However, I already tried to specifysep=","
or even revome the commas from the CSV but the dataset analysis isn't done properly
– Paulos
Dec 30 '18 at 20:39
1
You have a quote missing inbasket
. If i doread.transactions("file.csv", format = 'basket', sep=",")# transactions in sparse format with 13 transactions (rows) and 32 items (columns)
– akrun
Dec 30 '18 at 20:40
@IceCreamToucan the dataset isn't analyzed properly. For instance, it is saying that all rows have only 2 elements (it must be using only the first two numbers). Instead, it should be detecting the first as a class and the following (separeted by commas), as the elements.
– Paulos
Dec 30 '18 at 20:41
I think you need to specify the
sep
– akrun
Dec 30 '18 at 20:38
I think you need to specify the
sep
– akrun
Dec 30 '18 at 20:38
What happens when you try the code? An error? What error?
– IceCreamToucan
Dec 30 '18 at 20:38
What happens when you try the code? An error? What error?
– IceCreamToucan
Dec 30 '18 at 20:38
@akrun, thanks for your comment. However, I already tried to specify
sep=","
or even revome the commas from the CSV but the dataset analysis isn't done properly– Paulos
Dec 30 '18 at 20:39
@akrun, thanks for your comment. However, I already tried to specify
sep=","
or even revome the commas from the CSV but the dataset analysis isn't done properly– Paulos
Dec 30 '18 at 20:39
1
1
You have a quote missing in
basket
. If i do read.transactions("file.csv", format = 'basket', sep=",")# transactions in sparse format with 13 transactions (rows) and 32 items (columns)
– akrun
Dec 30 '18 at 20:40
You have a quote missing in
basket
. If i do read.transactions("file.csv", format = 'basket', sep=",")# transactions in sparse format with 13 transactions (rows) and 32 items (columns)
– akrun
Dec 30 '18 at 20:40
@IceCreamToucan the dataset isn't analyzed properly. For instance, it is saying that all rows have only 2 elements (it must be using only the first two numbers). Instead, it should be detecting the first as a class and the following (separeted by commas), as the elements.
– Paulos
Dec 30 '18 at 20:41
@IceCreamToucan the dataset isn't analyzed properly. For instance, it is saying that all rows have only 2 elements (it must be using only the first two numbers). Instead, it should be detecting the first as a class and the following (separeted by commas), as the elements.
– Paulos
Dec 30 '18 at 20:41
|
show 5 more comments
1 Answer
1
active
oldest
votes
I have tried to create a sample data using data provided by you
data <- read.table(text="Day Item
1 12,19,24,31,48,
1 1,19,
1 16,28,32,45,
1 19,36,41,43,44,
1 7,24,27,
1 21,31,33,41,
1 46
1 50
2 12,31,36,48,
2 17,29,47,
2 2,18,20,29,38,39,40,41
2 17,29,47",header = T)
data <- as(data[-1], "transactions") ##removing 1st header column for the transactional data
inspect(data)
## apply apriori algorithm ###
rules <- apriori(data, parameter = list(supp = 0.001, conf = 0.80))
### Arrange top 10 rules by lift ####
inspect(rules[1:10])
Please try this method hope it helps
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53981209%2fr-package-arules-read-transactions-file-format%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I have tried to create a sample data using data provided by you
data <- read.table(text="Day Item
1 12,19,24,31,48,
1 1,19,
1 16,28,32,45,
1 19,36,41,43,44,
1 7,24,27,
1 21,31,33,41,
1 46
1 50
2 12,31,36,48,
2 17,29,47,
2 2,18,20,29,38,39,40,41
2 17,29,47",header = T)
data <- as(data[-1], "transactions") ##removing 1st header column for the transactional data
inspect(data)
## apply apriori algorithm ###
rules <- apriori(data, parameter = list(supp = 0.001, conf = 0.80))
### Arrange top 10 rules by lift ####
inspect(rules[1:10])
Please try this method hope it helps
add a comment |
I have tried to create a sample data using data provided by you
data <- read.table(text="Day Item
1 12,19,24,31,48,
1 1,19,
1 16,28,32,45,
1 19,36,41,43,44,
1 7,24,27,
1 21,31,33,41,
1 46
1 50
2 12,31,36,48,
2 17,29,47,
2 2,18,20,29,38,39,40,41
2 17,29,47",header = T)
data <- as(data[-1], "transactions") ##removing 1st header column for the transactional data
inspect(data)
## apply apriori algorithm ###
rules <- apriori(data, parameter = list(supp = 0.001, conf = 0.80))
### Arrange top 10 rules by lift ####
inspect(rules[1:10])
Please try this method hope it helps
add a comment |
I have tried to create a sample data using data provided by you
data <- read.table(text="Day Item
1 12,19,24,31,48,
1 1,19,
1 16,28,32,45,
1 19,36,41,43,44,
1 7,24,27,
1 21,31,33,41,
1 46
1 50
2 12,31,36,48,
2 17,29,47,
2 2,18,20,29,38,39,40,41
2 17,29,47",header = T)
data <- as(data[-1], "transactions") ##removing 1st header column for the transactional data
inspect(data)
## apply apriori algorithm ###
rules <- apriori(data, parameter = list(supp = 0.001, conf = 0.80))
### Arrange top 10 rules by lift ####
inspect(rules[1:10])
Please try this method hope it helps
I have tried to create a sample data using data provided by you
data <- read.table(text="Day Item
1 12,19,24,31,48,
1 1,19,
1 16,28,32,45,
1 19,36,41,43,44,
1 7,24,27,
1 21,31,33,41,
1 46
1 50
2 12,31,36,48,
2 17,29,47,
2 2,18,20,29,38,39,40,41
2 17,29,47",header = T)
data <- as(data[-1], "transactions") ##removing 1st header column for the transactional data
inspect(data)
## apply apriori algorithm ###
rules <- apriori(data, parameter = list(supp = 0.001, conf = 0.80))
### Arrange top 10 rules by lift ####
inspect(rules[1:10])
Please try this method hope it helps
answered Dec 31 '18 at 4:18
HunaidkhanHunaidkhan
821114
821114
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53981209%2fr-package-arules-read-transactions-file-format%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2M ThxektB 22nUl72bTL
I think you need to specify the
sep
– akrun
Dec 30 '18 at 20:38
What happens when you try the code? An error? What error?
– IceCreamToucan
Dec 30 '18 at 20:38
@akrun, thanks for your comment. However, I already tried to specify
sep=","
or even revome the commas from the CSV but the dataset analysis isn't done properly– Paulos
Dec 30 '18 at 20:39
1
You have a quote missing in
basket
. If i doread.transactions("file.csv", format = 'basket', sep=",")# transactions in sparse format with 13 transactions (rows) and 32 items (columns)
– akrun
Dec 30 '18 at 20:40
@IceCreamToucan the dataset isn't analyzed properly. For instance, it is saying that all rows have only 2 elements (it must be using only the first two numbers). Instead, it should be detecting the first as a class and the following (separeted by commas), as the elements.
– Paulos
Dec 30 '18 at 20:41