0

I have two sets(a and b). I try to use %in% to choose all values in a, that are also in b.

The set a is read from text file using the following code:

a <- read.table("filename.txt")
names(a) <- c("time","A")

the output from this table read is like this

a <- data.frame(time = seq(0,20,0.2), A = seq(1,20,0.0333))

The set b is shown as the following format,

b <- data.frame(x = seq(1,20,0.2))

To achieve the match purpose, I need to use %in% like this

a <- subset(a, time %in% b$x)

Now an issue come out, some values in the a set are also in the b set.However, the return subset does not contain these value because they are considered no-match one.

I do not understand why this happen and how to fix this issue. Would you please give some suggestions to fix this problem?

Thanks

Hong

Hong
  • 31
  • 5
  • `b$x[2]==a$time[7]` is `FALSE`; `all.equal(b$x[2], a$time[7])` is `TRUE`. – Joshua Ulrich Sep 18 '16 at 22:42
  • Hi Joshua, thanks for your response. I have one more question to ask. I would like to get all items of A for the matched case (including those incorrect displayed one). How should I write the code for this? Regards – Hong Sep 19 '16 at 03:51
  • Your current code will work if you can convert `a$time` and `b$x` to integers because integers have exact binary representations. For example: `a$time <- as.integer(a$time*10); b$x <- as.integer(b$x*10); subset(a, time %in% b$x)`. – Joshua Ulrich Sep 19 '16 at 14:37

0 Answers0