Hi, I have a dataset like the one below, and I am trying to build histograms for every point in time, where I have the distribution on the y axis and those numerical variables on the x axis (with their respective mass). For example, for Jan 2008, I would like to get a histogram (this will serve me later to get a proper distribution) that maps the mass of answers to different values. Let me specify that the numbers under each column are the % of the respondents that falls into that category. I am trying to run a double loop as follow, but it does not work. Any suggestions?
Thanks in advance!
for (i in 2008:2021) {
for (j in 1:12) {
dfnew <- df[df$Year = i | df$Month = j ]
hist(dfnew)
}
}
For the sake of clarity, the variables are: month, year, -3, 0, 2, 4, 5.5, 8, 12.5, 15.
Month Year `-3` `0` `2` `4` `5.5` `8` `12.5` `15` `
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 2008 3 2 28 28 17 3 5 1 11
2 2008 5 3 26 27 15 4 6 1 11
3 2008 6 4 27 29 13 4 6 1 9
4 2008 9 4 18 26 16 5 7 1 12
5 2008 6 5 15 27 18 6 9 1 11
6 2008 8 3 17 26 15 6 10 2 11
7 2008 9 5 16 26 17 4 9 1 11
8 2008 5 5 19 27 14 5 9 2 12
9 2008 7 5 22 28 15 4 7 1 9