Vlad117 - 8 months ago 58

R Question

I have 3 data frames. One contains the whole set of numbers. Second and third data frames contain subsets of these numbers with a certain characteristic (type one or type two). What I would like to do is to merge these data frames into one so that each number is checked on being type one or type two.

Example:

`numbers <- c("+333","+334", "+335", "+443", "+444", "+445", "+553", "+554", "+555")`

typeone <- c("+333","+334", "+335", "+443")

typetwo <- c("+335", "+443", "+444", "+445")

fs <- data.frame(numbers)

to<- data.frame(typeone)

tt<- data.frame(typetwo)

Desired outcome after merging

`fs`

`to`

`tt`

`numbers typeone typetwo`

1 333 yes

2 334 yes

3 335 yes yes

4 443 yes yes

5 444 yes

6 445 yes

7 553

8 554

9 555

Answer Source

Try this:

```
data.frame(numbers = numbers,
typeone = numbers %in% typeone,
typetwo = numbers %in% typetwo)
```

Then you can change new logical columns however you want.