Home > Mobile >  How to use variable in xls file as input parameter
How to use variable in xls file as input parameter

Time:11-26

I usually declare some variables for next process input, but i want to move all variables into a separate xlsx file but still confused on how to call the variables

start_dt <- 20211001
end_dt <- 20211031

I'm expecting the variables are split just like above code so i can use each of them separately, but now they are in single vector

param_date <- read_excel("D:/Model/parameter.xlsx",sheet="date") %>% 
  as_vector()

enter image description here

enter image description here

CodePudding user response:

Based on your screenshots, the following should work to extract them:

param_date <- read_excel("D:/Model/parameter.xlsx",sheet="date") %>% 
  as_vector()
start_dt <- param_date[3]
end_dt <- param_date[4]

CodePudding user response:

modified my code, not 100% as i want but at least it can read header name as variable. still looking for a neater option to read directly from dataframe without additional step to declare each variable again.

param_date <- read_excel("D:/Model/parameter.xlsx",sheet="date") %>% 
  as.data.frame()

start_dt <- param_date[param_date$var=="start_dt",2]
end_dt <- param_date[param_date$var=="end_dt",2]
start_dt2 <- param_date[param_date$var=="start_dt2",2]
period <- param_date[param_date$var=="period",2]
  •  Tags:  
  • r
  • Related