Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201945

R for loop: How to compare ith row to every other row (including self) then ith+1 and so on and so forth

$
0
0

Let's say you have a table like this

| Column 1 |

| a|

| b|

| c|

| d|

| e|

| f|

and in the for loop you want to check each row against itself and everything else

like take in row one (a), and do something that checks it against a,b,c,d,e,f one at at a time (includes itself)

then take the next row (b),

and check it against a,b,c,d,e,f (includes itself) , then next row (c), etc, etc,

my orginal code was

for (i in 1:num_rows(dataframe){

[do stuff on the ith value, save result to a list] }

But this is missing many values, I think because it is not comparing to previously appearing rows There's something I found called seq_along but I'm confused about how it works.


Viewing all articles
Browse latest Browse all 201945

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>