Rearranging Columns in R Markdown

I am trying to rearrange my columns , any help? I want it to be Longitude, Proximal_sea, growing.air, and then Watershed as the last one

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

1 Like

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.