This is likely a very simple question, but I am trying to create a for loop function that would 1) find the percentage of "yes" from a column of "yes"/"no" for each variable in my df and 2) and then add that answer to a list to be used in a graph later.
So for example
j <- c("yes", "no", "no", "yes")
v <- c("no", "no", "no", "yes")
d <- c("yes", "no", "yes", "yes")
df <- data.frame(j,v,d)
df
frequency <- list()
for (i in df){
if(i == "Checked") {
freq <- #countif(df$i == "yes")/count(df, i)
frequency[[paste0("element", i)]] <- freq
}
}
I believe I am very far off as 1) I do not know how to count specific values only in a colulumn and 2) I am not able to add the output to a list.
My ideal output would be a list of fractions of "yes"/"total" for each of the variables in df. I want to then use the frequencies and variable names to create a bar chart of their frequencies (not directly related to this question, but just some context as to why I am trying to do accomplish this task.
Thank you for your help!