
However, I hope that the simplicity of the previous R programming examples helped to understand the logic of while-loops!ĭo you need further explanations on the content of this article? Then you may watch the following video of my YouTube channel. detailed break and exit conditions or using functions with multiple conditions) to generate more advanced outputs. Obviously you may make the content blocks within the while-loops more complex (e.g. Head(iris) # Showing head of updated dataĮach numeric variable was increased by 50. In this case, we first have to specify a running index that is increase with each iteration.

Until then, we want to add +50 to the values of the variable used in the current iteration. Let’s assume that we want to iterate through these variables until we reach the first non-numeric variable. The first four columns are numeric and the last column has the factor class.

# Sepal.Length Sepal.Width Petal.Length Petal.Width SpeciesĪs you can see, the iris flower data frame contains five columns. Head(iris) # Showing head of data in RStudio console Head (iris ) # Showing head of data in RStudio console # Sepal.Length Sepal.Width Petal.Length Petal.Width Species # 1 5.1 3.5 1.4 0.2 setosa # 2 4.9 3.0 1.4 0.2 setosa # 3 4.7 3.2 1.3 0.2 setosa # 4 4.6 3.1 1.5 0.2 setosa # 5 5.0 3.6 1.4 0.2 setosa # 6 5.4 3.9 1.7 0.4 setosaĭata(iris) # Loading exemplifying data set Data (iris ) # Loading exemplifying data set
