Dear sir,

I have 2 questions:

Question 1:
suppose that we have  the following:

a<-matrix(c(0,2,0,4,0,6,5,8,0),nrow=3)
colnames(a)<-c("F1","F2","F3")
rownames(a)<-c("A1","A2","A3")
a
ind <- which(a == 0, arr = TRUE)
mapply("[", dimnames(a), as.data.frame(ind))

I want to add a column to the result. This Column added depends on  the 2
first column value of the row.  The result should be something like this:


     [,1] [,2] [,3]
[1,] "A1" "F1" "A1 excludes F1"
[2,] "A3" "F1" "A3 excludes F1"
[3,] "A2" "F2" "A2 excludes F2"
[4,] "A3" "F3" "A3 excludes F3"


Question 2a)

I am also working with arules package and I have the following problem
let suppose the matrix b like:
b<-matrix(c(1,1,1,1,1,1,0,0,1,1,1,1,0,0,1,1,0,1,1,1,1,1,1,1),nrow=6)
rownames(b)=c("T1", "T2", "T3", "T4", "T5", "T6")
colnames(b)=c("It1", "It2", "It3", "It4")
bt<-as(b, "transactions")
rules<-apriori(bt, parameter = list(maxlen=2))
k<-inspect(rules)
k


##we obtain
  lhs      rhs     support confidence lift
1 {}    => {It4} 1.0000000          1  1.0
2 {}    => {It1} 1.0000000          1  1.0
3 {It3} => {It2} 0.5000000          1  1.5
4 {It3} => {It4} 0.5000000          1  1.0
5 {It3} => {It1} 0.5000000          1  1.0
6 {It2} => {It4} 0.6666667          1  1.0
7 {It2} => {It1} 0.6666667          1  1.0
8 {It4} => {It1} 1.0000000          1  1.0
9 {It1} => {It4} 1.0000000          1  1.0



WRITE(rules)

##we obtain

"rules" "support" "confidence" "lift"
"1" "{} => {It4}" 1 1 1
"2" "{} => {It1}" 1 1 1
"3" "{It3} => {It2}" 0.5 1 1.5
"4" "{It3} => {It4}" 0.5 1 1
"5" "{It3} => {It1}" 0.5 1 1
"6" "{It2} => {It4}" 0.666666666666667 1 1
"7" "{It2} => {It1}" 0.666666666666667 1 1
"8" "{It4} => {It1}" 1 1 1
"9" "{It1} => {It4}" 1 1 1

I want to convert this in a matrix or data frame and the result should be
something like this

##we obtain
  rules      support  confidence  lift
1 {}=>{It4}  1.0000000       1    1.0
2 {}=>{It1}  1.0000000       1    1.0
3 {It3}=>{It2}  0.5000000       1    1.5
4 {It3}=>{It4}  0.5000000       1    1.0
5 {It3}=>{It1}  0.5000000       1    1.0
6 {It2}=>{It4}  0.6666667       1    1.0
7 {It2}=>{It1}  0.6666667       1    1.0
8 {It4}=>{It1}  1.0000000       1    1.0
9 {It1}=>{It4}  1.0000000       1    1.0

In another hand is it possible to obtain all the rules where lHS<=>rhs?. In
our last example that means to obtain

  lhs      rhs     support confidence lift
8 {It4} => {It1} 1.0000000          1  1.0
9 {It1} => {It4} 1.0000000          1  1.0

Thanks again Alberto

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to