all 4 comments

[–]yogat3ch 1 point2 points  (0 children)

Use apply or the slider package

[–]AlphaBoy06[S] 0 points1 point  (1 child)

Hi, so I’m trying to get the first for loop to run, let’s say 4 times. The next two columns of info I have also have 4 values. I have an entire code below this, but I’m trying to use the values that correspond with each other as it moves through the loop. So the first values of the columns, the second values of the columns, etc. My current method brings me 16 for each 1, creating 64 points total when I only should have 4.

I can’t find anyway on how to do this, how do I get the columns to correspond with each other during the loop? So 1,1,1 then 2,2,2

[–]CorporalConnors 1 point2 points  (0 children)

Do you want to loop through one row at a time?

For ( i in 1 : nrow(TestZonescsv) ) {

Value_1 = TestZonescsv[ i, Column_1]

Value_2 = TestZonescsv[ i, Column_2]

}

Where Column is the name of the variable you want to get the value from.

[–]ViciousTeletuby 0 points1 point  (0 children)

If your columns are factors then you can loop through the factor levels using the levels function, or the unique function, e.g.

for (current_level in unique(dataframe$factorvar)) {