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

Find point in dataframe where (col_1[ i ], col_2[ i ]) = (col_1[ j ], -col_2[ j ])

$
0
0

There might be an obvious solution to this that I have missed but here goes:

Consider the data frame below. I wish to create a column with TRUE/FALSE values, where the value is TRUE whenever the condition (col_1[i], col_2[i]) = (col_1[j], -col_2[j]) is fulfilled. Note that sum() does not work here, since there might be a third value. To elaborate; what I have is:

col_1 <- c("x", "x", "y", "y", "y", "z", "z")
col_2 <- c(-1, 1, 3, -3, 4, 7, 3)
df <- data.frame(col_1, col_2)

enter image description here

What I want is:

enter image description here

I think the answer must be something with df %>% group_by(x), but I can't think of the complete solution.


Viewing all articles
Browse latest Browse all 201839

Trending Articles



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