-2

I am trying to add a title to this xtable

DATA5$Predict=predict(best.mod,newx=y2, type="class")
DATA5$armedornot2=ifelse(DATA5$armedornot!=1,"Yes","No")
DATA5$Predict=ifelse(DATA5$Predict <0.5, "No","Yes")
armedtable <- table(DATA5[,c("armedornot2","Predict")]) 
newtable<-cbind(armedtable,c(0,0))
xtable(newtable, caption=c("This is the title"), type="html", caption.placement="top")

However, this isn't working. I am also trying to change the V2 below to "No"

enter image description here

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
Vkara
  • 7
  • 2

1 Answers1

0

To change V2 to No, change cbind(armedtable,c(0,0)) to cbind(armedtable, No = c(0,0))

As for your caption, the issue is the printing. xtable itself doesn't take a type argument, it's print.xtable that determines the type (and the caption.placement). Try this:

print(xtable(newtable, caption=c("This is the title")),
      type="html", caption.placement="top")
Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
  • I'm trying to knit to html, and it wont show up correctly if i use print. Is there any other way to do it? – Vkara Dec 02 '19 at 20:29
  • That shouldn't be an issue. Did you set your chunk option to `results = "asis"`? Maybe make a reproducible example? – Gregor Thomas Dec 02 '19 at 20:51
  • When i put that in the chunk, it doesn't come out right. It comes out like this: % latex table generated in R 3.6.1 by xtable 1.8-4 package % Mon Dec 2 18:31:31 2019. – Vkara Dec 02 '19 at 23:36
  • Are you using the `type = "html"` argument, in the `print` not in the `xtable`, as in my code? It sounds like you're not... If I run `print(xtable(head(mtcars), caption = "Title here"), type = "html", caption.placement = "top")` it starts with ` – Gregor Thomas Dec 03 '19 at 02:24