How we can merge only column names lion and lion2 =''lion'' $ buffalo and buffalo2= ''buffalo'' in rmarkdown kable() function , could you have an idea?
It is not really clear what you are trying to do but I think your attempt to create a data.frame will not work. My best guess in that you are trying to do something like this.
lion <-"newt" # new chanced to "newt" because "new" is a function name.
lion2 <- "old"
buffalo <- "newt" # new chanced to "newt" because "new" is a function name.
buffalo2<- "old"
animal <- c(lion, lion2, buffalo, buffalo2)
price <- c(150, 200, 500, 750)
animal_data <- data.frame(animal,price)
animal_data
This gives us this, which I suspect is not what you want.
animal price
1 newt 150
2 old 200
3 newt 500
4 old 750
thank you for your help. you are correct the code was not correct. I have edit the code . my question is how we can merge two column names in to one single name in rmarkdown. if you have an idea please help me . thank you in advance
This is the output your code currently produces. Are you saying you want the same 2x4 table, but with column names "lion, lion, buffalo, buffalo"? Repeated column names are not a good idea.
col_name<- c("new","old","new","old")
price <- c(150,200,500,750)
weghts<- c(220, 330,800,900)
animal_data <- rbind(price,weghts)
colnames(animal_data) <- col_name
animal_data<- data.frame(animal_data)
# by defual if the column names duplicate , it gives .1 after the duplicate name
names(animal_data) <- gsub('[.].+', '', names(animal_data))
library(knitr)
library(kableExtra)
kable(animal_data) %>%
add_header_above(c(" " = 1, "lion" = 2, "buffalo" = 2))%>%kable_styling(latex_options = "scale_down")
thank you for your link, now I got, how I can prepare r markdown tables in such cases
I modified the original code by adding one more rows to create a data.frame and use the new and old rows as column names, remove duplicates using gsub() function then add_headers_above function to add lion and buffalo main columns. thank you