Using knitr and Rstudio, I'm trying to print a dataframe to HTML or Word, so that the leading whitespaces in versicolor, will push versicolor to the right.
#data
library(knitr )
library(xtable)
df <- iris[c(1,51),c(5,1)]
df$Species <- as.character(df$Species)
df$Species[ df$Species=="versicolor"] <- " versicolor"
Trying different combinations of kable()...
#table
kable( df)
kable( df, right = FALSE,align = c("l", "l" ) )
kable( df, right = FALSE,align = c("r", "l" ) )
I get this:
...or this:
But I'm trying to get this:
If you're willing to muck with some HTML:
df$Species[ df$Species=="versicolor"] <-
"<code style='background:white'> </code>versicolor"` will get you something like you want
or
df$Species[ df$Species=="versicolor"] <-
"<span style='padding-left:30px'> versicolor</span>"
will get you left-space-padding.
The latter might even be cleaner programmatically (inserting multiples of # in padding-left
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With