I will need to create a number of reference tables where I specify the number of academic credits a student is supposed to have to achieved, given a certain programme and time period.
I have a list of start dates and programmes for each individual student in the data frame "fulldata". As a first step, I want to use this data frame to get a list of unique start dates for a certain programme. Ideally, I would be able to automate this (and later) step(s) via a function since there are a lot of programmes.
At present I have three programmes, Economics(Ekonomi), Real Estate and Digital Media. I have three corresponding R-objects (containing a vector of academic credits for each module in order) named "Ekonomi", "Real Estate" and "Digital media". I want to fetch the unique values of start_date from "fulldata" where the program name equals the name of my current R object
I write:
start_dates<-function(x){
sd<-fulldata%>%filter(program==deparse(substitute(x)))%>%
dplyr::select(UTBILDNINGSTILLFALLE_STARTDATUM)%>%drop_na()%>%unique()
}
So for start_dates(Ekonomi)
the function should fetch the start dates for observations with programme equal to "Ekonomi". This does not seem to work however.
When i write
start_dates(Ekonomi)
sd
It turns out that sd does not contain any observations.
I can write:
sd<-fulldata%>%filter(program==deparse(substitute(Ekonomi)))%>%
dplyr::select(UTBILDNINGSTILLFALLE_STARTDATUM)%>%drop_na()%>%unique()
}
....and then sd turns out completely fine, but I don't seem to be able to do the same thing with a function.
What am I doing wrong and how can I make this work?
Small exerpt of data:
structure(list(UTBILDNINGSTILLFALLE_STARTDATUM = structure(c(15586,
15586, 15586, 15586, 15586, 15586, 15586, 15586, NA, 15586, 15586,
NA, 15586, 15586, 15586, NA, 15586, 15586, 15586, 15586), class = "Date"),
program = c("Ekonom", "Mäklarekonom", "Ekonom", "Mäklarekonom",
"Ekonom", "Ekonom", "Ekonom", "Ekonom", "Mäklarekonom", "Ekonom",
"Ekonom", "Mäklarekonom", "Ekonom", "Ekonom", "Mäklarekonom",
"Mäklarekonom", "Ekonom", "Ekonom", "Mäklarekonom", "Mäklarekonom"
)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-20L))