1

For some reason, it is not clear why my code for row col extraction is not working. This sample code should work.

set.seed(42)
FX <- data.frame(Location=c(5, 7:10), mi=c(1, 34.6, 6, 44, 5.55))
RX <- data.frame(Course=runif(n=1, min=4, max=5), Cor=runif(n=1, min=2, max=3))
FX
#   Location    mi
# 1        5  1.00
# 2        7 34.60
# 3        8  6.00
# 4        9 44.00
# 5       10  5.55
RX
#     Course      Cor
# 1 4.914806 2.937075

Current code that is not working:

which(FX==RX[1,1], arr.ind=TRUE)

Desired output:

Row and all cols

dcarlson
  • 9,058
  • 2
  • 13
  • 17
Toy L
  • 55
  • 6
  • 1
    Your example shows length difference – akrun Jul 29 '21 at 21:08
  • Is this [R FAQ 7.31](https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f)? Also [Why are these numbers not equal?](https://stackoverflow.com/questions/9508518/why-are-these-numbers-not-equal). – Rui Barradas Jul 29 '21 at 21:53
  • There are no values in `FX` which is equal to `RX[1,1]`. What is your expected output? – Ronak Shah Jul 30 '21 at 02:40
  • The expected output should be a value closest to it. – Toy L Aug 03 '21 at 03:38

1 Answers1

0

'RX' is just having a single row, We may need to replicate it to make the dimensions same

FX == RX[col(FX)]

Also, these are float values, so there is some precision involved i.e. it may not be exactly equal unless we do some rounding

akrun
  • 789,025
  • 32
  • 460
  • 575