Run a loop for each row in R
<p>I have been trying hard (as a beginner) to do this. I have a text where I would like to have some parts replaced with the row entries of a data frame (or matrix if that is easier).
I have an example dataset as follows:</p>

<pre><code>   x      y      z
1  5  apple  green
2  7 banana yellow
3 13  mango    red
</code></pre>

<p>I am stuck at this:</p>

<pre><code>for (x in mydata[["x"]]) {
    for (y in mydata[["y"]]) {
        for (z in mydata[["z"]]) {
            print(paste("The year is", x, y,"color", z))
        }
    }
}
</code></pre>

<p>However this renders texts with all possible combinations.
I want to get:</p>

<pre><code>"The year is 5 apple color green"
"The year is 7 banana color yellow"
"The year is 13 mango color red"
</code></pre>

<p>I have tried repeat, for, if, while but I get either the first, the last or an all combination return.
How can I define that I only want a sentence per row?</p>

<p>Thanks for your help.</p>