I am trying filtered data with value having 1 but the dataframe is already labelled . so the objective is to create a summary of filtered dataset
df <- data.frame(NY = c(1,2,1,1,2,1,1,1,2,1,1,1,2,1),
DE = c(2,2,1,1,1,2,2,1,1,1,2,2,2,1) )
df$NY<- factor(df$NY, levels =c(1,2), labels = c("available","unavailable"))
df$DE<- factor(df$DE, levels =c(1,2), labels = c("recieved","rejected"))
tbl <- function(df,col1,col2){
tb <- df %>% filter(col1== "available" & col2 == "recieved")
tb <- table(df[[col1]],df[[col2]]) %>% as.data.frame()
tb
}
output is the frequency of "available" in both column available/ total frequency in NY and DE for "recieved"
the output should be look like