Home > Software engineering >  How do I remove all variable names and leave values only in my export in R?
How do I remove all variable names and leave values only in my export in R?

Time:03-04

I have this code:

library(openxlsx)
library(tidyverse)

rid <- (c(1:20,NA))
RISN <- (c(1:20, NA))
Fake <- (c(1:20, NA))

df <- tibble(rid, RISN, Fake)

df <- df %>% filter(!is.na(rid) & !is.na(RISN)) %>% select(RISN,rid)

write.xlsx(df, "~/Downloads/df_test.xlsx", asTable = FALSE)

I need my export to appear like this with the "rid" and "RISN" column names removed. I'm not sure if this is possible. Does anyone know a way around this? I suspect I need to convert it from a tibble type to something else, but I've tried matrix and it's not working for me.

The columns should contain no headers

CodePudding user response:

One option would be to use colNames = FALSE. While not mentioned in the docs, under the hood write.xlsx calls buildWorkbook which calls either writeDataTable or writeData. Hence, you could use arguments mentioned in ?writeDataTable as well when using write.xlsx. These will be passed to writeDataTable via ....

library(openxlsx)
library(tidyverse)

rid <- (c(1:20,NA))
RISN <- (c(1:20, NA))
Fake <- (c(1:20, NA))

df <- tibble(rid, RISN, Fake)

df <- df %>% filter(!is.na(rid) & !is.na(RISN)) %>% select(RISN,rid)

write.xlsx(df, "df_test.xlsx", asTable = FALSE, colNames = FALSE)

Created on 2022-03-03 by the reprex package (v2.0.1)

  • Related