how to convert cbin result to make a bar plot

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

how to convert cbin result to make a bar plot

o_bouldjedri
Hi I am working on bayesina network using R and bnlearn package I can get the cpq using the code below but I wonder how can I plot a bar plot using the resulting format


library(bnlearn)
data(learning.test)
fitted = bn.fit(hc(learning.test), learning.test)
plot(hc(learning.test))
temp<-c(4)
learning.test<-learning.test[,-temp]
combn2 = expand.grid(lapply(learning.test[, "A", drop = FALSE], levels))
b<-cbind(as.data.frame(combn2), t(attr(predict(fitted, "D", combn2, prob =    
         TRUE, method = "bayes-lw"), "prob")))
>b
   A    a     b     c
 1 a 66.2 0.114 0.224
 2 b 21.4 0.672 0.114
 3 c 13.2 0.206 0.662

>b[,1:2]
   A    a
 1 a 66.2
 2 b 21.4
 3 c 13.2


I want to get this

    a    b      c
   66.2  21.4   13.2

>t(as.matrix(b[,1:2])
  [,1]   [,2]   [,3]  
A "a"    "b"    "c"  
a "66.2" "21.4" "13.2"

I don't want it to be a character

thanks