0

I'm trying to copy "product" names from rows associated with a match of "row.names". I have a list of row.names and I want to match them to a list of all the "row.names" I have, a master list. I want to copy the associated "product" names, but only the ones that match my list "row.names".

I have tried using Excel for this but I can't figure it out. So I'd like to try R and I have a elementary knowledge. I know about variables, assigning variables, calling up specific data etc but I don't know how to move data around and manipulate it in "R".

If my table looks like this

Row.names
3285c
3219c
6794a
5673a

I would like to compare it to my master table below and copy the product info from that master table, by matching row.names

Row.names  Product
5747c      apples
3257r      oranges
3219c      beans
5673c      pears

The outcome will filter all the non-matches out and leave only the row.name matches and the product names behind.

divibisan
  • 11,659
  • 11
  • 40
  • 58
dinesh
  • 1
  • 1

1 Answers1

0

You really should give a reproducible example, meaning input, output and expected result.

products <- read.delim(text = "Row.names
3285c
3219c
6794a
5673a", sep = " ", header = T)

master <- read.delim(text = "Row.names Product
5747c apples
3257r oranges
3219c beans
5673c pears", header = T, sep = " ")

master[master$Row.names %in% products$Row.names, ]
#>   Row.names Product
#> 3     3219c   beans
shosaco
  • 5,915
  • 1
  • 30
  • 48