My table is like this
family_group
col1 col2 col3
1 1 1
1 2 NA
2 3 NA
I am trying to loop through each column header and call it in the function, so I can create a graph for each header
I tried this:
for (val in colnames(family_group))
{
print(val)
intermediate_tables <- count(na.omit(family_group$val))
intermediate_frequency <-count(intermediate_tables$freq)
plot <- ggplot(data =intermediate_frequency, aes(x=intermediate_frequency$x, width = 0.5)) +geom_bar(aes(y=intermediate_frequency$freq), stat="identity", fill='lightgreen', color = 'green') +
geom_smooth(aes(y=intermediate_frequency$freq), method = 'loess') +
labs(x = "# of Samples in family", y = "# of families")
plot
}
when printing val, it does show "col1", "col2", and "col3"
but then when I am trying to call family_group$val, it gives None
How do I call each column through looping?
Thanks