Hi,
Welcome to the RStudio community!
You can simply use the select()
function from dplyr to get the columns you like and in the order you like. Here is an example:
library(dplyr)
library(knitr)
df = data.frame(x =runif(5), y = 1:5, z = LETTERS[1:5])
df %>% select(z, y) %>%
kable(format = "pipe", col.names = c("col z", "col y"))
col z | col y |
---|---|
A | 1 |
B | 2 |
C | 3 |
D | 4 |
E | 5 |
Created on 2023-02-21 by the reprex package (v2.0.1)
By the way, next time try to share your code as a reprex instead of a screenshot. A reprex consists of the minimal code and data needed to recreate the issue/question you're having. You can find instructions how to build and share one here:
Hope this helps,
PJ