Hi, new user here and new to R. I am working from an "ugly" Excel sheet with lots of extraneous columns and merged cells, etc. I want to create a new calculated column and then export it to Excel. I can do this, but what gets exported doesn't include the newly created column.
Here is my code:
# load needed libraries
library(readxl)
library(dplyr)
library(tidyr)
#read excel file into data frame
df_sch <- read_excel(path="C:/Users/USERNAME/OneDrive - NAME/Project Areas/Q&A Heatmap/LargeMedCenters/QACalculator_SCH_PostCOVID_2020.xlsm",sheet="Calculator",skip=7)
#pare down data frame to columns of interest using select()
df_sch2 <- select(df_sch,Metric,Domain,Measure,`Metric Value...23`,`Z-Score...24`,`% of Domain Score...25`,`Domain Rank...27`)
df_sch2 %>%
mutate(
Z_SCORE_24 = as.numeric(`Z-Score...24`),
PERCENTILE_RANK_NO = pnorm(Z_SCORE_24, lower.tail = FALSE)
)
df_sch2 %>% fill(Domain)
That produces the following:
I export to Excel using this code:
write_xlsx(df_sch2, "C:/Users/USERNAME/Documents/WorkingFiles/CC-Vizient_SystemRanking/Viz_ZscorePrctl_SCH.xlsx")
But what gets exported is the version with 7 columns. I need the version with 9 columns. Is there a way to specify which tibble to export? Is my fill code line overriding the mutate code? Something else? I would appreciate any help!