What does [i] designate?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

What does [i] designate?

WH_e-scientist
So I have a data frame that I am attempting to create several plots for. A colleague has located a script that was archived for a different project (from awhile ago), but the formula applies to my data set.

>par(mfrow=c(2,5))
>for (i in 1:length(EMP.daily)) {
+  boxplot(EMP.daily[,i], main=names(EMP.daily[i]), type="l")
+}

Unfortunately, my colleague does not have much information as to how each piece of this script functions so I have come to this forum to seek answers. I know I'm not providing all my info, but hopefully someone can provide some insight as to the purpose of some of these blocks of code.

1. I know that par() designates the parameters of the plot, but what does the for(...) function do when paired with it.

2. The function of 'i' both in the 'for(...)' function, but also in the square brackets '[i]' when designating what data to plot in the 'boxplot(...)' function.

I am extremely new to R so please let me know if I am posting this in the wrong thread or if there's a better way to present any future questions I may have.

Thanks!